Answer the question
In order to leave comments, you need to log in
Exception or new validator?
I saw it in the code where 15+ exceptions are caught, it looks very crooked and cumbersome, because you can write the same validator and return errors from it.
So what then and when is it more correct to use?
Answer the question
In order to leave comments, you need to log in
An exception is needed if the program cannot be continued. For example, if you need to get data from the database, but the connection to the database is not established. In this case, we call an exception, log the error and exit the program.
A validator is needed to validate data, such as input data, when you need to fill out some kind of form that has required fields. In this case, it is enough to return an array/object with errors and terminate the program. Validation errors are not program errors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question