php捕捉错误的方法:1、使用“try catch”语句捕获错误;2、通过“set_exception_handler”方法捕获错误,该方法用于设置用户自定义的异常处理函数。

PHP错误捕获处理
一般捕获错误使用的方法是:
try{
...
}catch(Exception $e){
echo $e->getMessage();
}或者
立即学习“PHP免费学习笔记(深入)”;
set_exception_handler(function ($exception) {
echo $exception->getMessage();
});示例:
';
echo $exception->getMessage();//参数错误
});
test();
}catch(Exception $e){
echo $e->getMessage();//参数错误
}set_exception_handler — 设置用户自定义的异常处理函数,用于没有用 try/catch 块来捕获的异常。
更多相关知识,请访问PHP中文网!










