w3resource

PHP error handling function set_exception_handler()

Description 

PHP set_exception_handler() calls a user-defined function as parameter for exception handling.

Version:

PHP 5

Syntax:

set_exception_handler (user-defined-function)

Parameter:

Parameters Description Required / Optional Type
user-defined-function A user defined function. Required callback

Return Values:

The function returns the name of the user-defined exception handler or NULL on error.

If no previous exception handler was defined, then also NULL is returned.

Example:

 <?php 
function w3r_exception_handler($w3r_exception) 
{   echo "Uncaught exception: " , 
$exception->getMessage(), 
"\n"; } 
set_exception_handler('w3r_exception'); 
throw new Exception('Uncaught Exception'); 
echo "Not Executed\n"; 
?> 

Previous: set_error_handler()
Next: trigger_error()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/error-handling/php-error-handling-function-set_exception_handler.php