Skip to content
Advertisement

How to pass error handling to a function in PHP?

I need to handle multiple types of error in many places in my PHP class in my Laravel project, and of course I don’t want to repeat error handling codes everywhere in my code.

I have this code now:

JavaScript

But the handleError() method isn’t called.

How can I pass the exceptions to my error handler method in PHP?

Advertisement

Answer

In Laravel, error and exception handling is already configured for you. No need to use custom class to achieve this.

All exceptions are handled by the AppExceptionsHandler class, you may customize report and render methods on this class:

JavaScript

See Error Handling on Laravel docs for more info.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement