laravel5異常錯誤-FatalErrorException in Handler.php line 38

瘋狂的麥克斯發表於2019-02-16

1、錯誤提示

FatalErrorException in Handler.php line 38:
Uncaught TypeError: Argument 1 passed to AppExceptionsHandler::report() must be an instance of Exception, instance of Error given, called in D:wwwactivityvendorcompiled.php on line 1817 and defined in D:wwwactivityappExceptionsHandler.php:38
Stack trace:
#0 D:wwwactivityvendorcompiled.php(1817): AppExceptionsHandler->report(Object(Error))
#1 [internal function]: IlluminateFoundationBootstrapHandleExceptions->handleException(Object(Error))
#2 {main}
thrown

原因:D:wwwactivityvendorcompiled.php on line 1817 的變數$e不是Exception的例項物件(對錯誤提示的翻譯……^.^笑cry)

2、解決方案
在提示的錯誤地方加上變數$e的例項判斷,如果不是Exception型別,就new一個

if (!$e instanceof Exception) {
    $e = new FatalThrowableError($e);
}

new完之後的樣子:


public function handleException($e)
{
    if (!$e instanceof Exception) {
        $e = new FatalThrowableError($e);
    }
    $this->getExceptionHandler()->report($e);
    if ($this->app->runningInConsole()) {
        $this->renderForConsole($e);
    } else {
        $this->renderHttpResponse($e);
    }
}

相關文章