What is the principle of PHP's exception mechanism? What is the last zend_handle_exception in PHP for each executable op array? Let's start with a question.
For a bit of code, onerror clearly executed, but Onexception did not execute, 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 a file in my name, so this file does not exist */
- require ("laruence.php");
Operation Result:
- Error occurred
- PHP Fatal Error:main (): Failed opening required ' laruence.php
First, we need to know that require throws two errors before and after it contains a problem that cannot be found:
1. WARNING: Thrown when PHP tries to open the file.
2. E_compile_error: The function that opened the file from PHP fails to be thrown after the failure.
And we know that Set_error_handler is not able to capture e_compile_error errors. So, in OnError, you can only catch the first warning error, and the exception thrown in OnError, why is it not captured by default Exception_handler? This is about PHP.
12 3 Next Page