[EDIT – Disclaimer: This is a really bad idea, see the accepted answer for an actual solution.]
I define my own exception handler using set_exception_handler() function. After the handler execution, I need the script to continue. Is there any way to do it?
Disclaimer: I know try-catch blocks but I need to process Exceptions dynamicaly. Every calling of Clazz::foo() specifies its own exceptions which should be caught by my handler. That’s the reason I can’t use it.
Example:
class Clazz {
private static $exceptions;
public static function foo(array $exceptions) {
set_exception_handler(array(__CLASS__, "exception_handler"));
self::$exceptions = $exceptions;
throw new RandomException;
echo "I need this to be printed!";
}
public static function exception_handler($exception) {
// process the exception in my way...
// if $exception in self::$exceptions than 1, else 2, fi
restore_exception_handler();
// continue in some way, like it has never happenned
}
}
This is just bad idea. I just hope you don’t understand how Exceptions work and you’re not meaning the question.
First of all, setting exception handler… Exception handler is called when the exceptions is propagated to main script (actually out of it) and your script is therefore done:
You should either use what’s Xeoncross suggesting, but I think you have problem with called function/method that is throwing exceptions so you can do this: