The function used to define the top-level exception handler is
set_exception_handler("My_exception");
My_expection here is the developer-defined exception handling function, which is the top-level exception handler. It can only handle exceptions when there is no function in the program. Only the top-level exception handler can handle exceptions. If no top-level exception handler is defined, the system default exception handler will handle exceptions
For example:
Copy the code The code is as follows:
< ?php
set_exception_handler("My_expection");
function My_expection(){
echo "Here is the top-level exception handler";
}
try{
nohello("hello" );
}catch(Exception $e){
throw $e;
}
function nohello($nohello){
if($nohello == "hello"){
throw new Exception("Cannot enter hello");
}else{
echo "Input successful";
}
}
?>
A question about PHP exception handling
Copy code The code is as follows:
try {
$a=10/0;
}catch (Exception $e){
echo "throws an exception";
}
?>
The above code , does not output "thrown exception", but outputs the error message: Warning: Division by zero in...
Explanation: There is no exception thrown in the try block, but according to The system's default error handling mechanism handles
so whether an exception can be caught depends on whether an exception is actually thrown.
http://www.bkjia.com/PHPjc/325572.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325572.htmlTechArticleThe function used to define the top-level exception handler is set_exception_handler("My_exception"); My_expection here is developer-defined The exception handling function, the top-level exception handler, only...