Laravel 5处理所有错误 [英] Laravel 5 handle all errors
问题描述
不确定在Laravel 5中如何做到这一点.在4中,您可以将App :: error(function(Exception $ exception,$ code){}块添加到routes.php文件中,它将用作毯子异常处理程序.我在Laravel 5中了解了它的工作原理,在其中您添加了对单个异常和自定义异常的处理,这很棒-但是否也存在一种全部捕获"处理机制?
Not sure how this is done in Laravel 5. In 4 you could add in App::error(function(Exception $exception, $code){} block to the routes.php file, and it would serve as a blanket exception handler. I get how it works in Laravel 5 where you add handling for individual exceptions and custom exceptions, which is great - but is there a sort of "Catch all" handling mechanism as well?
推荐答案
您可能需要自定义App\Exceptions\Handler
的render()
方法,如此处所述:
You would probably need to have to customize the render()
method of App\Exceptions\Handler
, as stated here : http://laravel.com/docs/5.0/errors#handling-errors
您可以编辑app/Exceptions/Handler.php
来完成工作:
You can edit the app/Exceptions/Handler.php
to do the job :
public function render($request, Exception $e)
{
//Your code here
return view('error');
}
这篇关于Laravel 5处理所有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!