Describes the process and principle of the PHP exception mechanism

Source: Internet
Author: User
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?

 
  1. Function onError ($ errCode, $ errMesg, $ errFile, $ errLine ){
  2. Echo "Error Occurred \ n ";
  3. Throw new Exception ($ errMesg );
  4. }
  5. Function onException ($ e ){
  6. Echo $ e-> getMessage ();
  7. }
  8. Set_error_handler ("onError ");
  9. Set_exception_handler ("onException ");
  10. /* I will never name the file with my name, so this file does not exist */
  11. Require ("laruence. php ");

Running result:

 
  1. Error Occurred 
  2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.