The function used to define the top-level exception handler is
Set_exception_handler ("My_exception");
The my_expection here is the developer's custom exception handler, which is the top exception processor, and only if there is no function in the program to handle the exception, there is a top-level exception handler to handle the exception, and if no top-level exception handler is defined, then the system default exception handler handles the exception
An example is provided:
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/><?php
Set_exception_handler ("My_expection");
function My_expection () {
echo "Here is the top exception handler";
}
try{
Nohello ("Hello");
}catch (Exception $e) {
Throw $e;
}
function Nohello ($nohello) {
if ($nohello = = "Hello") {
throw new Exception ("Can't enter Hello");
}else{
echo "Input Success";
}
}
?>
A problem with PHP exception handling
Copy Code code as follows:
<?php
try {
$a =10/0;
}catch (Exception $e) {
echo "Throws an exception";
}
?>
The above code, does not output "throw exception", but output error message: Warning:division by zero in ...
Description: Instead of throwing an exception in the try block, it is handled according to the system default error handling mechanism
So it's possible to catch an exception, depending on whether there's really a throw exception