Home > Article > Backend Development > PHP exception handling—set top-level exception handler
set_exception_handler() function sets a user-defined function that handles all uncaught exceptions.
The output of the above code should look like this:
In the above code, there is no "catch" block, but the top-level exception handler is triggered. This function should be used to catch all uncaught exceptions.
Exception rules
In short: if an exception is thrown, you must catch it.
The above introduces PHP exception handling - setting up the top-level exception handler, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.