The restore_exception_handler Function
The restore_exception_handler
function restores the previous exception handler,
which was replaced using set_exception_handler
. This function does not accept parameters
and does not return values.
Syntax
restore_exception_handler();
Example
Let's set a custom exception handler and then restore the previous one:
<?php
function customExceptionHandler($exception) {
echo 'Custom handler: ' . $exception->getMessage();
}
set_exception_handler('customExceptionHandler');
restore_exception_handler();
?>
Example
Let's verify that after restoring the handler, the standard mechanism works:
<?php
set_exception_handler(function($exception) {
echo 'Handler 1: ' . $exception->getMessage();
});
set_exception_handler(function($exception) {
echo 'Handler 2: ' . $exception->getMessage();
});
restore_exception_handler();
throw new Exception('Test error');
?>
Code execution result:
'Handler 1: Test error'