Answer the question
In order to leave comments, you need to log in
When should custom Exceptions be made?
Having delved into the topic of exceptions :) I was puzzled by the following question:
- In what cases may it be necessary to create your own exceptions?
After all, there are already quite a few ready-made ones both in SPL and in frameworks?
What good reason would there be to throw your own exception?
Answer the question
In order to leave comments, you need to log in
Native exceptions are needed in cases where you want to handle (or, if you're a library author, provide handling capabilities for) some exceptional scenario in a special way. For example, look at how exceptions are organized in Doctrine.
Also, custom exceptions can be useful if you want to pass some additional information with this exception. For example, look at the exceptions for different HTTP status responses in Symfony.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question