PHP语法毛病捕捉处置惩罚
平常捕捉毛病运用的要领是:
try{ ... }catch(Exception $e){ echo $e->getMessage(); }
或许
set_exception_handler(function ($exception) { echo $exception->getMessage(); });
示例:
<?php function test(){ throw new Exception('参数毛病'); } try{ //假如catch没有捕捉到,才会实行到这里 set_exception_handler(function ($exception) { echo $exception;//exception 'Exception' with message '参数毛病' in /www/web/...(一堆信息) echo '<br>'; echo $exception->getMessage();//参数毛病 }); test(); }catch(Exception $e){ echo $e->getMessage();//参数毛病 }
set_exception_handler
— 设置用户自定义的非常处置惩罚函数,用于没有用 try/catch 块来捕捉的非常。
引荐教程:PHP视频教程
以上就是php语法毛病捕捉的细致内容,更多请关注ki4网别的相干文章!