Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel Daily:
Laravel Exceptions: How to Catch, Handle and Create Your Own
Apr 23, 2018 @ 16:25:10

On the Laravel Daily site they've posted a tutorial showing the Laravel users out there how to create and catch custom exceptions in your application. Exceptions are a useful tool to handle "exceptional situations" where something fails badly enough where the application cannot proceed.

Quite often web-developers don’t care enough about errors. If something goes wrong, you often see default Laravel texts like “Whoops, something went wrong” or, even worse, the exception code, which is not helpful at all to the visitor. So I decided to write a step-by-step article of how to handle errors in elegant way and present proper error information to the visitor.

He uses a "user search" task to help illustrate the methods for creating custom exceptions, catch exceptions and showing the error to the user. Code is included as well as screenshots of the output. With the basics of exception handling out of the way, they move the handling off into a service and take it one step further to create a custom "user not found" exception and its use in the search method.

tagged: laravel exception tutorial handling create catch custom

Link: http://laraveldaily.com/how-to-catch-handle-create-laravel-exceptions/


Trending Topics: