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.