PHP Error: Exception thrown without a stack frame in Unknown on line 0[reprint]

Source: Internet
Author: User
Tags php error

From: NetEase Blog

As far as I know, in both cases PHP will report Exception thrown without a stack frame in Unknown on line 0 error:

1) Abnormal capture with Set_exception_handler guide, exception inside perform another exception

As in the following code, this problem occurs:

http://de.php.net/manual/de/function.set-exception-handler.php#88082

functionError_Handler ($code,$message,$file,$line){    if(0 = =error_reporting())        return; Throw NewErrorexception ($message, 0,$code,$file,$line);}functionException_handler ($e){    //... normal exception stuff goes here    Print $undefined;//This is the underlying problem}Set_error_handler("Error_Handler");Set_exception_handler("Exception_handler");Throw New Exception("Just Invoking the exception handler");

Print $undefined in the Exception_handler function; the line itself throws an exception, and he goes back to calling Set_exception_handler's Exception_handler function, which is a dead loop.

Workaround: Do not perform another exception in one exception

The above problem can be used in a try ... catch way, such as exception_handler change to the following:

functionException_handler ($e){    Try    {        //... normal exception stuff goes here        Print $undefined;//This is the underlying problem    }    Catch(Exception $e)    {        Print Get_class($e). "Thrown within the exception handler. Message: ".$e->getmessage (). "On line".$e-GetLine (); }}

2) Throwing an exception in a destructor

Refer to this bug:http://bugs.php.net/bug.php?id=33598

The following code will report this error:

classTest {function__construct () {Echo"Construct\n"; }    functiongreet () {Echo"Hello world\n"; }     function__destruct () {Echo"Destruct\n"; Throw New Exception(' Test ' ); }}$test=Newtest ();$test->greet ();

Current Solutions:

1. Do not throw an exception in a destructor.

2. Because the destructor is executed at exit, manually unset the kind and catch the exception.

For example above, in the last add a line unset ($test), then the program will be reported throw new Exception (' Test '); This line has errors, and then catch this exception on the line.

The above two cases will appear in PHP 5.2.11, as for reasons I think PHP may be this way, PHP bug 33598 in 2005, the bug status is closed, stating that the official does not think that this is a bug, or improper handling of a bug.

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.