The Set_exception_handler () function sets a user-defined function to handle all uncaught exceptions.
Exception: ", $exception->getmessage ();} Set_exception_handler (' myexception '); throw new Exception (' uncaught exception occurred ');? >
The output of the above code should look like this:
Exception:uncaught Exception occurred
In the above code, there is no "catch" code block, but the top-level exception handler is triggered. You should use this function to catch all uncaught exceptions.
Rules for exceptions
- The code that requires exception handling should be placed inside a try code block to catch a potential exception.
- Each try or throw code block must have at least one corresponding catch code block.
- You can use multiple catch blocks to catch different kinds of exceptions.
- You can throw (re-thrown) exceptions again in a catch code block within a try code block.
In short: If an exception is thrown, it must be captured.
The above describes the PHP exception handling-Set the top-level exception handler, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.