Launching Drycomponents - Get Free HTML/React Components built using TailwindCSS

Registering Custom Exception Handler in Laravel 5

In this article I’m going to guide you on how to register the custom exception handler in laravel. There might be a situation where you needed separate exception handler instead of default one like module based development. So, I’m going to help you in registering your first custom exception handler in laravel. Let’s get started

Creating Handler File

By default, all the exceptions are handled by App\Exceptions\Handler. So first, under the app/Exceptions folder we need to create a new Handler.php file with the following content to handle exceptions throwed by laravel.

Registering Custom Exception Handler

Now that we have exception handler class ready, we have to register the class. You can do that by binding the laravel’s exception handler class and our custom handler class like the following

Now whenever there is an exception App\Exceptions\CustomerHandler class will be called instead of default App\Exceptions\Handler class.

Happy Coding!

Would like to hear more from me?

Consider Signing up. No spam ever.