Simple question but can't seem to find the answer.
If I have a php class, is it possible to register an exception handler for the whole class?
The reason I want to do this is that my class uses objects that are part of my domain model. These object's methods throw very explicit exceptions. I don't want these exceptions to bubble up to higher level classes, but instead want to catch all these exceptions and throw them as a more general exception e.g. DomainLayerException
I would therefore like one area in my class that catches any number of a list of exceptions I define from my domain model, and throws them as a more general exception e.g.
Currently the way I do this is by wrapping method calls to the domain objects in a try catch block. This is getting very messy as I use more and more domain objects and their methods. Would be great to remove these try catch blocks and handle them all on one place in the class i.e. if any exception is thrown in the class, it is caught by a single event handler defined in the class