php语法错误捕获

互联网 19-10-10

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语法错误捕获的详细内容,更多内容请关注技术你好其它相关文章!

来源链接:
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
标签: 捕获
上一篇:php获取远程图片并下载保存到本地的方法分析 下一篇:php date函数时间不对

相关资讯