What is the principle of the PHP exception mechanism? What is the ZEND_HANDLE_EXCEPTION at the end of every oparray that can be executed independently in PHP? Let's start with a question. For the code, onError is executed, but onException is not executed. why? & Lt ;? Php & nbsp; function & nbsp; onError ($ errCo what is the principle of the PHP exception mechanism? What is the ZEND_HANDLE_EXCEPTION at the end of each op array that can be executed independently in PHP? Let's start with a question.
For the code, onError is executed, but onException is not executed. why?
-
- Function onError ($ errCode, $ errMesg, $ errFile, $ errLine ){
- Echo "Error Occurred \ n ";
- Throw new Exception ($ errMesg );
- }
- Function onException ($ e ){
- Echo $ e-> getMessage ();
- }
- Set_error_handler ("onError ");
- Set_exception_handler ("onException ");
- /* I will never name the file with my name, so this file does not exist */
- Require ("laruence. php ");
Running result:
- Error Occurred
- PHP Fatal error: main(): Failed opening required 'laruence.php
First, we need to know that when Require contains a problem that cannot be found, two errors will be thrown before and after:
1. WARNING: thrown when PHP tries to open this file.
2. E_COMPILE_ERROR: it is thrown after the function of opening the file from PHP fails to return.
As we know, set_error_handler cannot catch the E_COMPILE_ERROR error. Therefore, in onError, only the first WARNING error can be caught, but the exception thrown in onError is not caught by the default exception_handler? Let's talk about PHP.
12 3 Next page