Difference between error and exception in php and Its Application

Source: Internet
Author: User
This article mainly introduces the difference between error and exception in php and its application. For more information, see

This article mainly introduces the difference between error and exception in php and its application. For more information, see

The difference between error and exception. For more information, refer to java. It seems that the exception handling process in php is similar to that in java.

The Object Inheritance structure in java is as follows:

Object ----> Throwable --------> Exception ----> RuntimeException | Error
Errors are of the unchecked type. Exceptions are of the checked and unchecked types.
And regard exceptions and errors as abnormal program running.

To distinguish between exceptions and errors:
Exception: non-fatal. Try {} catche (Exception e) {} The try module in execution is a test run, and the code is run incorrectly (non-fatal error ).
The exception works like the following code:

If (mysql_connect ('2017. 0.0.1 ', 'root', '000000') {echo 'database connection successfully'; // other code ...} else {echo 'database connection error'; return false ;}

With exception handling, you can easily handle exceptions. The following code can handle many exceptions at a time:

Try {mysql_connect ('2017. 0.0.1 ', 'root', '123'); // other code you want to execute} catche (Exception $ e) {print_r ($ e );}

Error: fatal. Generally, errors are caused by program syntax errors or user-level prompts.

Errors and exceptions are divided into checked and unchecked
Checked can be processed by users. unchecked cannot be processed.
Exception in php. user-level errors can be handled by users (client code). Other errors cannot be handled by users.
In addition, there is a RuntimeException in java that cannot be processed by the user. This is a running-level exception.

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.