php捕获谬误的办法:一、应用“try catch”语句捕捉谬误;二、经过“set_exception_handler”办法捕捉谬误,该办法用于设置用户自界说的异样解决函数。
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若何捕获谬误的具体内容,更多请存眷资源魔其它相干文章!
标签: php php教程 php故障解决 php使用问题 捕捉错误
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!