PHP exception Handling-Set top-level exception handler

Source: Internet
Author: User
Tags php exception handling
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.