The flow and principle of PHP exception mechanism

Source: Internet
Author: User

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?

 
 
  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 a file in my name, so this file does not exist */ 
  11. require ("laruence.php");

Operation Result:

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