PHP Exception handling class, PHP exception handling _php Tutorial

Source: Internet
Author: User
Tags php exception handling

PHP Exception handling class, PHP exception handling


PHP has many exception handling classes, where exception is the base class for all exception handling.

Exception has several basic properties and methods, including the following:

Message content for exception messages
Code exception Codes
File name that throws an exception
Line throws an exception in the number of lines of the file

Among the methods commonly used are:

Gettrace getting exception tracking information
Gettraceasstring string that gets the exception trace information
GetMessage getting error messages

If necessary, you can create a custom exception-handling class by inheriting the exception class.

Custom exception class, inherited PHP exception base class Exceptionclass MyException extends Exception {    function getInfo () {        return ' custom error message ';    }} The try {    //function that uses the exception should be in the "try"  code block. If no exception is triggered, the code will continue to execute as usual. However, if an exception is triggered, an exception is thrown.    throw new MyException (' Error ');//This specifies how to trigger an exception. Note: Each "throw" must correspond to at least one "catch", which can of course correspond to multiple "catch"} catch (Exception $e) {//"catch" code block catches an exception and creates an object containing the exception information    Echo $e- >getinfo ();//Gets the custom exception information    echo $e->getmessage ();//Gets GetMessage information inherited from the base class}

http://www.bkjia.com/PHPjc/963547.html www.bkjia.com true http://www.bkjia.com/PHPjc/963547.html techarticle PHP exception handling class, PHP exception handling PHP has a lot of exception handling classes, where exception is the base class for all exception handling. Exception has several basic properties and methods, including the following: ...

  • 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.