PHP7 Error Handling

Source: Internet
Author: User
The current PHP has been released to version 7.
I've been studying it for the last two days.
Now the new error handling and exception handling methods are not very clear how to use
I hope the great God can give an example

    try {        not_exists_func();    } catch (\EngineException $e) {        echo $e->getMessage();    }

The above code does not throw an exception, what is it for?

Reply content:

The current PHP has been released to version 7.
I've been studying it for the last two days.
Now the new error handling and exception handling methods are not very clear how to use
I hope the great God can give an example

    try {        not_exists_func();    } catch (\EngineException $e) {        echo $e->getMessage();    }

The above code does not throw an exception, what is it for?

PHP7 implements a global Throwable interface, the original exception and partial error both implement this interface (interface) and define the inheritance structure of the exception in the way of the interface. As a result, more error in PHP7 becomes a exception that can be captured and returned to the developer, error if not captured, and if the capture becomes a exception that can be processed within the program. These catch-all error is usually an error that does not cause fatal damage to the program, such as a function that does not exist.

\ What's this for?

Shouldn't you be new? What's this?

Try to remove it with a exception scratch


  
   getMessage());}output:string(44) "Call to undefined function not_exists_func()"

Open Error Report?

ini_set("display_errors", 1);error_reporting(E_ALL^E_NOTICE);
  • 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.