#36826 [Asn->Bgs]: Throwing an exception inside an exception handler catch block causes fatal

From: Date: Tue, 11 Apr 2006 11:54:27 +0000
Subject: #36826 [Asn->Bgs]: Throwing an exception inside an exception handler catch block causes fatal
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-95598@lists.php.net to get a copy of this message
 ID:               36826
 Updated by:       dmitry@php.net
 Reported By:      qlogix at gmail dot com
-Status:           Assigned
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Centos 4.1
 PHP Version:      5.1.2
 Assigned To:      dmitry
 New Comment:

Yes. exception_handler, that is set with set_exception_handler(),
catches exceptions those are uncaught by PHP script. The handler is not
executed in context of PHP script (it is executed without any context),
and it cannot throw exceptions.


Previous Comments:
------------------------------------------------------------------------

[2006-04-11 11:27:08] sniper@php.net

Dmitry, I think this was intentional behaviour, but can you confirm
this?

------------------------------------------------------------------------

[2006-03-22 22:43:38] qlogix at gmail dot com

Description:
------------
Throwing an exception from inside a catch block within an exception
handler function causes a fatal error.

If I comment out the marked line, the fatal error does not occur.

I would expect PHP to re-call the master exception handler function.

Reproduce code:
---------------
class TestException extends Exception { }
set_exception_handler('handler');

function handler($ex)
{	
	/* Just to rule out recursion */
	if ($ex instanceof TestException) {	die("Recursion"); }	
	try 
	{		
		/* This is where I would attempt to write to the db */
		throw new Exception("someDBFunction failed");				
	}
	catch (Exception $ex)
	{	
		/* If I comment out the following line, the error goes away */
		throw new TestException("The db logging function failed..write to
file.");		
	}	
}
throw new Exception("Ex");

Expected result:
----------------
The script should die with the message "Recursion"

Actual result:
--------------
Fatal error: Exception thrown without a stack frame in Unknown on line
0


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=36826&edit=1


Thread (3 messages)

« previous php.bugs (#95598) next »