PHP 7 Error Handling

Source: Internet
Author: User
The current PHP version has been released to version 7. Two days ago, I have studied the new error handling and exception handling methods, but I don't quite understand how to use them. I hope you can give an example {code ...} the above Code cannot throw an exception. Why? PHP has been released to version 7.
I also studied it two days ago.
The new error handling and exception handling methods are not very clear about how to use them.
Hope you can give an example

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

The above Code cannot throw an exception. Why?

Reply content:

PHP has been released to version 7.
I also studied it two days ago.
The new error handling and exception handling methods are not very clear about how to use them.
Hope you can give an example

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

The above Code cannot throw an exception. Why?

PHP7 implements a global throwable interface. The original Exception and some errors both implement this interface and define the inheritance structure of exceptions in the form of interfaces. As a result, more errors in PHP 7 become caught exceptions and are returned to the developer. If no capture is performed, the Error is returned. If the capture is performed, the Exception can be processed in the program. These captured errors are usually errors that do not cause fatal damage to the program. For example, functions do not exist.

\ What is this?

Shouldn't it be new? Why?

Try to capture with Exception


  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);

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.