After working with Laravel for a while and learning about its way of handling exception, I found myself creating my own exceptions, either to simplify some if/else statements or to terminate function calls or even features. #content Content #understanding-custom-exceptions #structuring-custom-exceptions #making-exceptions-simple-and-extensible #standardizing-errors #creating-the-jsonencodeexception #understanding-custom-exceptions Understanding custom exceptions Laravel can handle custom exceptions automatically when the exception is created in a certain way.

Here, an abstract class gets defined to enforce that every exception will implement a status(), help() and error() functions. At the render() function, that we are overriding from the Exception class, we are using the result of the implementation of our help and error methods to create an error object.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners