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.