In the daily project development process, there will always be some of our unexpected anomalies, if we do not have a relatively perfect treatment, then the program looks very unprofessional, it is likely to become the effective information of others attacking the system; Some error exceptions terminate script execution. This time without some error message, then we can only look at the code from the beginning, to know how the hundreds of thousands of lines of code in the project is a terrible thing for us, then how we in the process of development of the project quickly and accurately locate the exception, error, and the corresponding processing, This article by oneself to the error, the exception processing understanding, again this sharing and everybody mutual study exchanges, and as a memo.
system error Handler :
PHP Normally, errors will be normal output, but in some frameworks, may affect the wrong output, it may be the framework itself has its own processing mechanism, or it may be processed in the code, usually these function settings:
1.error_reporting (); Set the error level for PHP and return to the current level
Error_reporting (Report_level)
If the parameter level is not specified, the current error levels are returned. The following items are possible values for level:
Value |
Constant |
Describe |
1 |
E_error |
Fatal run-time error. This error cannot be reclaimed. The script was interrupted to execute. |
2 |
E_warning |
A non-fatal run-time warning. The script is not interrupted to execute. |
4 |
E_parse |
Parse error at compile time. Resolve errors that should be generated only by the parser |
8 |
E_notice |
Run-time notifications. The script is found to be an error, but it can also occur when a script is typically run |
16 |
E_core_error |
Fatal error when PHP is started. This is like E_error in the PHP core. |
32 |
E_core_warning |
Warning when PHP is started. This is like e_warning in the PHP core. |
64 |
E_compile_error |
Fatal compile-time error. This is like passing the e_error generated by the Zend scripting engine. |
128 |
E_compile_warning |
Non-fatal compile-time warning. This is like passing the Zend scripting engine to generate e_warning |
256 |
E_user_error |
Fatal user generated error, which is similar to the programmer using PHP function trigger_error () setting E_error |
512 |
E_user_warning |
Non-fatal user generated warnings, which are similar to programmers using PHP functions trigger_error settings e_warning |
1024 |
E_user_notice |
User generated notifications, which are similar to programmers using PHP functions trigger_error settings E_notice |
2048 |
E_strict |
Run-time notifications. PHP recommends changing your code to help with the interoperability and compatibility of the code |
4096 |
E_recoverable_error |
A fatal error that can be captured, similar to E_error, but can be captured by a user-defined handler (see Set_error_handler ()) |
8191 |
E_all |
All errors and warnings except level e_strict (in PHP6.0, E_strict will be part of E_all) |
It is worth noting that the error output is turned off when the $level is 0, which means that no errors are output.
2.set_error_handler ()
Definition and usage
The Set_error_handler () function sets the user-defined error-handling function.
This function is used to create the user's own error handling method during runtime.
The function returns the old error handler and returns null if it fails.
Grammar
Set_error_handler (Error_function,error_types)
Parameters |
Describe |
Error_function |
Necessary. Specifies the function to run when an error occurs. |
Error_types |
Optional. Specifies the error reporting level at which user-defined errors are displayed. The default is "E_all". |
Tip: If you use this function, the standard PHP error handler is completely bypassed , and if necessary, the user-defined error handler must terminate (Die ()) script,
Note: If an error occurs before the script executes, the custom error handler is not used because the custom program is not registered at that time.
PHP error handling mechanism