I'm creating a new plugin and I want to handle errors cleanly. I find the WP_Error class unwieldy so have decided to use exceptions. I am not bothered about lack of PHP 4 support.
$error = true;
if ($error) {
// Throw an error
throw new CustomException('A custom exception');
}
What I really want to be able to do is throw exceptions as per the code above in my plugin (and use try/catch blocks where appropriate), but when there is an uncaught exception, I want to be able to set an error handler ie:set_exception_handler()
that only catches uncaught exceptions from my plugin. So if another theme exception handler has been set already, it doesn't interfere.
Even better would be if I intercepted any of my plugin exceptions, dealt with them as appropriate, and then could choose to forward them onto any other already set exception handlers.
Is this possible? Or is it possible to set an exception handler that only catches exceptions from within the class it is set? I was thinking along the lines of creating a customException that extended Exception and then somehow having a custom catch-all exception handler for it.