Laravel 5 - adding logic to throw exceptions from package

I am developing a package for Laravel 5 and I would like to add rendering logic for my own default exceptions ExceptionHandler

.

I don't want to replace the default Laravel 5 exception handler, I just want the application where my package is installed to know how my package exceptions should be displayed.

How can i do this? Thank:)

+3
php exception exception-handling laravel laravel-5


source to share


1 answer


If you would like to replace your application exception handler, you can do so in your service provider. While it would be nice to propagate from an application exception handler, it would be tricky because it couldn't be named App\Excpetions\Handler

if the developers changed the application namespace.

$app->singleton(
    'Illuminate\Contracts\Debug\ExceptionHandler',
    'Vendor\Package\ExceptionHandler'
);

      



Otherwise, you might consider providing a trait that a developer can use in their own ExceptionHandler

and thus leverage your additional functionality.

+2


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics