Php exception handling

Source: Internet
Author: User
: This article mainly introduces the php exception handling class. if you are interested in the PHP Tutorial, refer to it. PHP has many Exception handling classes, of which Exception is the base class for handling all exceptions.

Exception has several basic attributes and methods, including:

Message exception message content
Code exception code
File name that throws an exception
Line throws an exception on the number of lines in the file.

Common methods include:

GetTrace
GetTraceAsString string used to obtain exception tracking information
GetMessage

If necessary, you can inherit the Exception class to create a custom Exception handling class.

// The custom Exception class inherits the Exception base class Exceptionclass MyException extends Exception {function getInfo () {return 'custom error information';} of PHP ';}} try {// The abnormal function should be located in the "try" code block. If no exception is triggered, the code continues as usual. However, if an exception is triggered, an exception is thrown. Throw new MyException ('error'); // specifies how to trigger an exception. Note: Each "throw" must correspond to at least one "catch". of course, multiple "catch"} catch (Exception $ e) {// "catch" code blocks can catch exceptions, create an object that contains the exception information echo $ e-> getInfo (); // Obtain the custom exception information echo $ e-> getMessage (); // Get the getMessage information inherited from the base class}

The above introduces the php exception handling class, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.

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.