How to create and store your own exception classes?

Hello! I use to own exception classes. For example, a class comment should throw an exception "CommentException"class, and adding posts "AddPostException", in order not to stop the execution of a script using just \Exception, because it is used in the entry point for processing and returns any errors.

So you have to create empty subclasses CommentException, AddPostException:
class CommentException extends \Exception{};
class AddPostException extends \Exception{};

Which usually create these subclasses? In the class file and class you add a post or maybe it creates a separate file that keeps all the null exception and is connected at the entry point, or the exceptions have their own file that is called by the startup when you call?

How to solve this problem are constantly generated empty classes extending the Exception only to make clear catch, what exception to catch now?
March 12th 20 at 08:05
2 answers
March 12th 20 at 08:07
-if you divide the domains functionality
in any case, this is a separate catalogue of Exceptions and separate class
March 12th 20 at 08:09
They are usually generated in the ACC. policy namespaces, separate files, even if the exception itself is empty.

Find more questions by tags PHP