Home > Backend Development > PHP Tutorial > PHP exception handling technology, top exception handler_PHP tutorial

PHP exception handling technology, top exception handler_PHP tutorial

WBOY
Release: 2016-07-21 15:18:04
Original
959 people have browsed it

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.

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template