In this article, you will learn how to get the previous exception handler in PHP. The restore_exception_handler() function in PHP restores the previous exception handler. This function is used to restore the previous exception handler after changing it with the set_exception_handler() function.
what is the syntax of the RESTORE_EXCEPTION_HANDLER() function in php?
restore_exception_handler();
examples of the function
Example 1. In this example, we restore the exception handler example.
<?php
// Two user-defined exception handler functions
function myException1($exception) {
echo "[" . __FUNCTION__ . "]" . $exception->getMessage();
}
function myException2($exception) {
echo "[" . __FUNCTION__ . "]" . $exception->getMessage();
}
set_exception_handler("myException1");
set_exception_handler("myException2");
restore_exception_handler();
// Throw exception
throw new Exception("This triggers the first exception handler...");
?>