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.