Laravel 5.5 Adds Support for Custom Exception Reporting


April 17th, 2017

In Laravel 5.5 it will be possible to define a report method on any custom exception. Laravel will look for the existence of the report method on any exception that it catches in the Illuminate\Foundation\Exceptions\Handler class.

if (method_exists($e, 'report')) {
    return $e->report();

This is a convenient place to send a notification email to the developer, report to your application monitoring software, or carry out any other action you may require in the event the exception is thrown.

In previous versions of Laravel, it was possible to achieve the same result by editing the report method of the App\Exceptions\Handler class. Here you can listen for an instance of a particular exception and carry out your action accordingly.

public function report(Exception $exception)
    if ($exception instanceof MyException) {
        // do something here such as send an email to developer or notify monitoring app

    return parent::report($exception);

As you can imagine, as your application grows, this can become a little messy and difficult to maintain.

This small change coming to Laravel 5.5 will make a huge difference in ensuring this is no longer an issue.

Filed in:

Joe Dixon

Founder and CTO of ubisend. Proud Father to two tiny heroes, Husband, developer, occasional globetrotter.