The set_exception_handler() function sets a user-defined exception handling function.
This function is used to create the user's own exception handling method during runtime.
This function returns the old exception handler, or NULL if it fails.
set_exception_handler(exception_function)
parameter | describe |
---|---|
exception_function | Required. Specifies the function to be called when an uncaught exception occurs. This function must be defined before calling the set_exception_handler() function. This exception handling function requires one parameter, which is the thrown exception object. |
Tip: After this exception handler is called, the script stops executing.
<?phpfunction myException($exception){echo "<b>Exception:</b> " , $exception->getMessage();}set_exception_handler('myException');throw new Exception('Uncaught Exception occurred');? >
The output of the above code looks like this:
Exception: Uncaught Exception occurred