English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Error & Loggings Reference Manual
The set_exception_handler() function sets a user-defined exception handling function
string set_exception_handler ( callback $exception_handler );
If try / If an exception is not caught in the catch block, this function sets the default exception handler. After calling exception_handler, execution will stop.
Serial Number | Parameters and Description |
---|---|
1 | exception_handler The name of the function to be called when an uncaught exception occurs. This function must be defined before calling set_exception_handler(). This handler function needs to accept one parameter, which will be the exception object thrown. |
It returns the name of the previously defined exception handler, or NULL if an error occurs. If no previous handler is defined, NULL is also returned.
The following is the usage of this function-
<?php function exception_handler($exception) { echo "The uncaptured exception is: " , $exception->getMessage(), "\n"; } set_exception_handler('exception_handler'); set_exception_handler(); throw new Exception('No exception found'); echo "Not including the executed\n"; ?>Test and see‹/›
Output result:
The uncaptured exception is: No exception found