php中异常处理和捕获

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zchqq/article/details/82895546
try {

    要执行的代码.......

} catch (\Error $e){
    return ['status'=>'Error','error_msg'=>$e->getMessage()];
} catch (\Exception $e) {
    return ['status'=>'Exception','error_msg'=>$e->getMessage()];
} catch (\Throwable $e) {
    return ['status'=>'Throwable','error_msg'=>$e->getMessage()];
}


Exception
->getMessage 异常消息内容
->getPrevious 返回异常链中的前一个异常
->getCode 获取异常代码
->gitFile 获取发生异常的程序文件名称
->getLine 发生异常的代码行号
->getTrace 获取异常追踪信息
->__toString 将异常对象转换为字符串

Fatal 致命错误,脚本终止运行
Parse 编译时解析错误,语法错误,脚本终止运行
Warning 警告错误 脚本不终止运行
Notice 通知错误,脚本不终止运行
 

猜你喜欢

转载自blog.csdn.net/zchqq/article/details/82895546