php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36826 Throwing an exception inside an exception handler catch block causes fatal
Submitted: 2006-03-22 22:43 UTC Modified: 2006-04-11 11:54 UTC
Votes:6
Avg. Score:4.5 ± 0.8
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:0 (0.0%)
From: qlogix at gmail dot com Assigned: dmitry (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.2 OS: Centos 4.1
Private report: No CVE-ID: None
 [2006-03-22 22:43 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-11 11:27 UTC] sniper@php.net
Dmitry, I think this was intentional behaviour, but can you confirm this?
 [2006-04-11 11:54 UTC] dmitry@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 13:01:30 2024 UTC