Home Rendering and Reporting Exceptions

Enter a search term to find articles.
2018-09-19
206

Rendering and Reporting Exceptions

If you need a more robust reporting of your Exceptions, you can just add a report() method to your exception classes. Laravel will auto-detect that (and the render method) and run the logic inside.

What's the difference between render and report in Exception classes?

In render method you will typically want to return a response of some type (json/view), while report method you will typically want to Log the exception (file/database). And if you are using some 3rd party reporting tool like Sentry or Bugsnag you will want to call that in the report method as well.

    use Exception;
    use Illuminate\Support\Facades\Log;

    class FooException extends Exception
    {
        /**
         * Report the exception.
         *
         * @return void
         */
        public function report()
        {
            // Using simple Log
            Log::warning($this->getMessage());

            // Using 3rd party integration like Sentry or Bugsnag
            app('sentry')->captureException($this);
        }
    }

Marvin Quezon

Full Stack Web Developer
Marvin Quezon · Copyright © 2024 · Privacy · Sitemap