Introduction to PHP7 error handling mechanism

Source: Internet
Author: User
Tags error handling exception handling throwable

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

One, there are now two exception classes: Exception and Error.

PHP7 now has two exception classes, Exception and Error. All two classes implement a new interface: Throwable. In your exception handling code, type hinting may need to be adjusted.

<?php

try {
Not_exists_func ();
catch (Engineexception $e) {
Var_dump ($e->getmessage ());
}

Output
String "Call to undefined function not_exists_func ()"

Second, some fatal errors and recoverable fatal errors are instead thrown at the error object.

Some fatal errors and recoverable fatal errors are now reported to the Error object. The error objects are independent of the exception, and they cannot be caught by conventional try/catch. Editor's note: You need to register the error handling function, please refer to the following RFC.
The recoverable fatal error that has turned into an exception cannot be ignored silently by the error handler. In particular, type hinting errors cannot be ignored.

Third, the grammatical error will throw a ParseError object

A syntax error throws a ParseError object that inherits from the Error object. When you process eval (), you should also capture the ParseError object in addition to checking the return value or Error_get_last () for potentially incorrect code.

Four, the internal object construction method if it fails, always throws an exception

The construction method of the inner object always reports an exception if it fails. Some previous construction methods return null or an object that cannot be used.

Five, some e_strict wrong level adjustment.

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.