這是明擺着的異常處理程序;,在app/start/global.php
默認情況下已經上市,修改爲如下(順便說一句,Whoops! PHP Errors only for Cool Kids):
App::error(function(Exception $exception)
{
Log::error($exception);Log::error($exception->getMessage());
return View::make('errors.index')->with('exception', $exception);
});
創建一個視圖view/errors/index.blade.php
@extends('layouts.master')
@section('content')
<div class="page-header">
<h1>Oops!</h1>
</div>
<div class='well'>ERROR: {{ $exception->getMessage() }}</div>
@stop
另外,還要'debug' => false
在app/config/app.php
文件:
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => false,
,可以有以下方法$exception
對象使用:
array (size=10)
//0 => string '__construct' (length=11)
1 => string 'getSeverity' (length=11)
2 => string 'getMessage' (length=10)
3 => string 'getCode' (length=7)
4 => string 'getFile' (length=7)
5 => string 'getLine' (length=7)
6 => string 'getTrace' (length=8)
7 => string 'getPrevious' (length=11)
8 => string 'getTraceAsString' (length=16)
//9 => string '__toString' (length=10)
如果您離開'debug' => true,
,那麼您的異常處理程序仍然可以正常工作,但在某些情況下,它可能會在異常未在您處理程序中捕獲時顯示whoops
,而在通用Exception
處理程序之前的另一個特定處理程序中顯示。
還要記住,Exception
類是最通用的異常類型,如果在此之後定義了其他更具體的異常處理程序,那麼如果從該特定處理程序返回任何響應,則不會觸發它。
男人簡直太容易了,不要拿掉答案。謝謝@ WereWolf - 阿爾法 – Chris