这是普通的异常处理程序;默认情况下已在 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
同时在你的app/config/app.php 文件中创建'debug' => false:
/*
|--------------------------------------------------------------------------
| 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,,那么您的异常处理程序仍然可以工作,但在某些情况下,当异常未在您的处理程序中捕获但在通用Exception 处理程序之前的另一个特定处理程序中时,它可能会显示whoops。
还请记住,Exception 类是最通用的异常类型,如果您在此之后定义了其他更具体的异常处理程序,那么如果从该特定处理程序返回任何响应,它将不会被触发。