thinkphp5 Exception類重定義

重點定義本身的錯誤信息和錯誤碼;php

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

// 異常處理handle類 留空使用 \think\exception\Handleapp

'exception_handle'       => '',
指錯誤信息來自自於\think\exception\Handle的方法裏;那麼能夠從新定義一個類,再重寫這個hander方法便可;
======================================
1.定義config:
'exception_handle'       => 'app\lib\exception\ExceptionHandler',
2.在app\lib\exception\ExceptionHander.php中:
class ExceptionHandler extends Handle
{
    public function render(Exception $e)
    {
        return json('這裏是自定義的錯誤');
        //return parent::render($e); // TODO: Change the autogenerated stub

    }
}
相關文章
相關標籤/搜索