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.