Difference between error and exception in php and Its Application: errorexception

Source: Internet
Author: User

Difference between error and exception in php and Its Application: errorexception

The difference between error and exception. For more information, see the online documentation. 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('127.0.0.1','root','321321');    // 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.


Error is different from exception?

Error indicates that recovery is not a serious problem that is impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such a situation.

Exception indicates a design or implementation problem. That is to say, it indicates that if the program runs normally, it will never happen.

This is a professional answer for the interview question.

What is the difference between error and exception?

Error indicates that recovery is not a serious problem that is impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such a situation. Exception indicates a design or implementation problem. That is to say, it indicates that if the program runs normally, it will never happen.

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.