PHPackages                             cerbero/exception-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. cerbero/exception-handler

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

cerbero/exception-handler
=========================

Extend Laravel exception handler to define how to handle custom exceptions via service providers.

3.0.0(5y ago)607.5k↓50%5MITPHPPHP ^7.2

Since Apr 17Pushed 5y ago2 watchersCompare

[ Source](https://github.com/cerbero90/exception-handler)[ Packagist](https://packagist.org/packages/cerbero/exception-handler)[ Docs](https://github.com/cerbero90/exception-handler)[ Fund](https://paypal.me/AndreaMarcoSartori)[ RSS](/packages/cerbero-exception-handler/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (6)Versions (6)Used By (0)

Exception Handler
=================

[](#exception-handler)

[![Author](https://camo.githubusercontent.com/73e6f53653e58136b44a6406e113f7d984da8b77f44227e0159538d0a16061db/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406365726265726f39302d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/cerbero90)[![Latest Version on Packagist](https://camo.githubusercontent.com/67499465089f3f2a077b2995d28e77d721a9384d96f328bdf92173e73295dbb4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6365726265726f2f657863657074696f6e2d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cerbero/exception-handler)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/9712af0aff9ba2b5abe6aa561395754ad5b7950db1314ff725fc43d661ffb7b0/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6365726265726f39302f657863657074696f6e2d68616e646c65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/cerbero90/exception-handler)[![Coverage Status](https://camo.githubusercontent.com/3e2cff7c117858db07f23bdfaba1b7bd9fc31b45fd6554de95e24f0f53cd6080/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6365726265726f39302f657863657074696f6e2d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cerbero90/exception-handler/code-structure)[![Quality Score](https://camo.githubusercontent.com/48cb806cb04779de7fa13f0178db4d41027e97b64d55942852949645238fd707/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6365726265726f39302f657863657074696f6e2d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cerbero90/exception-handler)[![Total Downloads](https://camo.githubusercontent.com/7c5c8671435803f19bdab08b086b217ed9b318ba65b9b8ed69e06e7cbdb43cf7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6365726265726f2f657863657074696f6e2d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cerbero/exception-handler)

[![SensioLabsInsight](https://camo.githubusercontent.com/691726c8463962dfab3631bf31b0347305df59bddbea4049daa0e7fe9767506a/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f36393664326635642d656137652d343834612d386530362d3833366463623436326231392f6269672e706e67)](https://insight.sensiolabs.com/projects/696d2f5d-ea7e-484a-8e06-836dcb462b19)

This Laravel package lets you define the behavior of your application when a specific exception is thrown.

Laravel handles exceptions in `app/Exceptions/Handler.php` by default, but the more handlers you add the more this class gets cluttered and difficult to read and maintain.

Furthermore it is not possible for an external Laravel package to automatically register how its custom exceptions should be handled by the application where it has been installed.

This package lets you register custom exception handlers by using service providers, so that also external packages may register their own.

> **Please note:** this package leverages the decorators design pattern, which allows you to keep using the Laravel default handler as you normally would. It just wraps the exception handler to extend its functionalities.

Install
-------

[](#install)

Via Composer

```
composer require cerbero/exception-handler
```

If your Laravel version is prior to 5.5, please add this service provider in `config/app.php`

```
'providers' => [
    ...
    Cerbero\ExceptionHandler\Providers\ExceptionHandlerServiceProvider::class,
]
```

Usage
-----

[](#usage)

There are 3 types of handlers that can be registered:

- **Reporters**, they log an exception or report it to an external service (e.g. Sentry, Bugsnag...)
- **Renderers**, they render an exception into an HTTP response
- **Console Renderers**, they render an exception to the console

The following examples show how to register each type of handler in the `boot()` method of a service provider:

```
use App\Exceptions\DebugException;
use App\Exceptions\ArtisanException;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Validation\ValidationException;

...

public function boot()
{
    // register a custom reporter to log all exceptions that are instances of - or extend - DebugException
    $this->app->make(ExceptionHandler::class)->reporter(function (DebugException $e) {
        $this->app['log']->debug($e->getMessage());
    });

    // register a custom renderer to redirect the user back and show validation errors
    $this->app->make(ExceptionHandler::class)->renderer(function (ValidationException $e, $request) {
        return back()->withInput()->withErrors($e->errors());
    });

    // register a custom console renderer to display errors to the console and stop the propagation of other exceptions
    $this->app->make(ExceptionHandler::class)->consoleRenderer(function (ArtisanException $e, $output) {
        $output->writeln('' . $e->getMessage() . '');
        return true;
    });
}
```

A handler is basically a callback that accepts the exception to handle as first parameter. You can register a global handler by omitting the exception type or type-hinting `Exception`.

Unlike reporters, renderers also accept a second parameter: an instance of `Illuminate\Http\Request` in case of a renderer or a `Symfony\Component\Console\Output\OutputInterface` in case of a console renderer.

It is also important to note that all registered handlers for an exception will be called until one of them returns a truthy value, in that case the exceptions propagation stops.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Andrea Marco Sartori](https://twitter.com/cerbero90)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~530 days

Total

4

Last Release

2091d ago

Major Versions

1.0.0 → 2.0.02019-09-28

2.0.1 → 3.0.02020-08-27

PHP version history (3 changes)1.0.0PHP ~5.5|~7.0

2.0.0PHP ^5.5|^7.0

3.0.0PHP ^7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/596523?v=4)[Matteo Picciolini](/maintainers/cerbero)[@cerbero](https://github.com/cerbero)

---

Top Contributors

[![cerbero90](https://avatars.githubusercontent.com/u/5838106?v=4)](https://github.com/cerbero90 "cerbero90 (15 commits)")

---

Tags

laravelexceptionsexception handler

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/cerbero-exception-handler/health.svg)

```
[![Health](https://phpackages.com/badges/cerbero-exception-handler/health.svg)](https://phpackages.com/packages/cerbero-exception-handler)
```

###  Alternatives

[bugsnag/bugsnag-laravel

Official Bugsnag notifier for Laravel applications.

90334.6M36](/packages/bugsnag-bugsnag-laravel)[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[inspector-apm/inspector-laravel

Code Execution Monitoring, built for developers.

2332.0M2](/packages/inspector-apm-inspector-laravel)[jackwh/laravel-new-relic

Monitor your Laravel application performance with New Relic

112827.2k](/packages/jackwh-laravel-new-relic)[keepsuit/laravel-opentelemetry

OpenTelemetry integration for laravel

142347.8k](/packages/keepsuit-laravel-opentelemetry)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
