thinkphp5 Exception类重定义

重点定义自己的错误信息和错误码;

在TP5的配置文件中有下面一段

// 异常处理handle类 留空使用 hinkexceptionHandle

'exception_handle'       => '',
指错误信息来自自于 hinkexceptionHandle的方法里;那么可以重新定义一个类,再重写这个hander方法即可;
======================================
1.定义config:
'exception_handle'       => 'applibexceptionExceptionHandler',
2.在applibexceptionExceptionHander.php中:
class ExceptionHandler extends Handle
{
    public function render(Exception $e)
    {
        return json('这里是自定义的错误');
        //return parent::render($e); // TODO: Change the autogenerated stub

    }
}
原文地址:https://www.cnblogs.com/bing2017/p/8135893.html