Laravel 5.5 Adds Support for Custom Exception Reporting

Laravel 5.5 Adds Support for Custom Exception Reporting

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: Laravel 5.5 / Exceptions


Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Senior Quality Assurance Engineer
Bisnow Media
Senior PHP/Laravel Developer: Your Dream Work Environment
iPhone Photography School
Senior Software Engineer
Remote or San Francisco
Laravel Developer
Las Vegas, NV
V Shred
R&D Developer
Denver, CO
Full-Stack Developer
Paris, France