The following is an article about error handling and exception handling in PHP. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the following small series to bring you an article on error handling and exception handling in PHP. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at it with Xiaobian.
Error handling:
1. Syntax error
2. runtime errors
3. logical error
Error report:
Error E_ERROR
Warning E_WARNING
Note E_NOTICE
Development Phase: all error reports are output during development, which facilitates debugging.
Running stage: Do not let the program output any error report
Write Error reports to logs
1. specify error report error_reporting = E_ALL (in php. inn)
2. disable error output display_errors = off (in php. ini)
3. enable the error log function log_errors = on (in php. ini)
1. if no error log location is specified by default, logs are written to the web server by default.
2. specify a file name for the error_log option. the file name is an error log.
3. error_log = syslog
";?>
Exception handling:An unexpected event occurs during the running of the program. An exception is used to change the normal process of the script.
A new important feature in PHP5
Try {
} Catch (exception object ){
}
1. if there is no problem with the code in try, it will be executed after the code in try is executed.
2. if an exception occurs in the code in try, an exception object (throw) is thrown to the catch parameter, and the content after the exception code appears in try is not executed, directly jump to the catch to execute, the catch is completed, and then continue to execute downward
"; $ File = @ fopen ("./hello.txt "," r "); if (! $ File) {throw new Exception ("file opening failed");} echo "2222222222
";} Catch (Exception $ e) {echo" 3333333
"; Echo $ e-> getMessage ()."
"; Touch (" hello.txt "); $ file = @ fopen ("./hello.txt "," r ");} echo" 4444444
";?>
In the above discussion, the error handling and exception handling in PHP are all the content that I have shared with you. I hope you can give us a reference and support me a lot.