鍍金池/ 問答/PHP  C  HTML/ tp5.1 接口開發(fā) 異常層的問題

tp5.1 接口開發(fā) 異常層的問題

利用thinkphp5.1x做接口開發(fā),做一個全局異常的處理層.

class ExceptionHandler extends Handle {
    private $code;
    private $msg;
    private $errCode;
    public function render(\Exception $e)
    {
        if($e instanceof BaseException){
        //    自定義的異常
            $this->code=$e->code;
            $this->msg=$e->msg;
            $this->errCode=$e->errCode;
        }else{
        // 系統(tǒng)的異常,判斷是不是調(diào)試模式:是,顯示tp5的異常,否則顯示封裝接口的異常
            if(config('app.app_debug')){
                //使用系統(tǒng)的錯誤提示
                parent::render();
            }else{
                $this->code=500;
                $this->msg='服務器內(nèi)部錯誤';
                $this->errCode=999;
                //寫入日志
            }
        }

我輸入一個錯誤的路由:顯示了一個致命錯誤
圖片描述

為啥沒有捕獲到異常,我需要怎么修改我的代碼了?

回答
編輯回答
檸檬藍

已解決
return parent::render($e);
上面沒有把參數(shù)傳遞進去

2017年11月25日 16:50