Home >Backend Development >PHP Tutorial >PHP exception handling technology, top exception handler PHP custom exception c# exception handling java exception handling
php handles exceptions the same as java, using try{}catch(){}
The function used to define the top-level exception handler is
set_exception_handler("My_exception");
here My_expection is a developer-defined exception handling function, which is a top-level exception handler. Only when there is no function in the program to handle exceptions will there be a top-level exception handler to handle exceptions. If no top-level exception handler is defined, the system defaults to it. Exception handler to handle exceptions
Example:
<meta http-equiv="content-type" c />
<?<span>php </span><span>set_exception_handler</span>("My_expection"<span>); </span><span>function</span><span> My_expection(){ </span><span>echo</span> "这里是顶级异常处理器"<span>; } </span><span>try</span><span>{ nohello(</span>"hello"<span>); }</span><span>catch</span>(<span>Exception</span><span>$e</span><span>){ </span><span>throw</span><span>$e</span><span>; } </span><span>function</span> nohello(<span>$nohello</span><span>){ </span><span>if</span>(<span>$nohello</span> == "hello"<span>){ </span><span>throw</span><span>new</span><span>Exception</span>("不能输入hello"<span>); }</span><span>else</span><span>{ </span><span>echo</span> "输入成功"<span>; } } </span>?>
Reprinted from: http://blog.sina.com.cn/s/blog_641d5693010121cr.html
The above introduces PHP exception handling technology, the top exception handler, including exception handling, PHP content, I hope it will be helpful to friends who are interested in PHP tutorials.