php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32101 Exception in unknown on line 0 when throwing exception inside exception handler
Submitted: 2005-02-25 07:12 UTC Modified: 2010-03-25 21:32 UTC
Votes:18
Avg. Score:4.6 ± 0.8
Reproduced:16 of 18 (88.9%)
Same Version:5 (31.2%)
Same OS:10 (62.5%)
From: ceefour at gauldong dot net Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5CVS-2005-02-15 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ceefour at gauldong dot net
New email:
PHP Version: OS:

 

 [2005-02-25 07:12 UTC] ceefour at gauldong dot net
Description:
------------
When an exception is thrown inside an exception handler, a "exception thrown without stack frame in unknown on line 0" message is displayed.

While the meaning of this message is "clear" enough... it doesn't help at all.

If you trigger_error() inside an error handler, the default error handler is triggered, but still showing meaningful/helpful error message. Exceptions inside exception handler should behave similarly.

Reproduce code:
---------------
// do this inside an exception handler function
throw new Exception('test'); 

Expected result:
----------------
...file something.php on line 483...

Actual result:
--------------
...unknown on line 0....

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-25 11:01 UTC] tony2001@php.net
<?php
function exception_handler($exception) {
	trigger_error("user error");
	throw new Exception('exception1');
}
set_exception_handler('exception_handler');
throw new Exception('exception2');
?>
 [2005-02-25 11:20 UTC] ceefour at gauldong dot net
This modified code may be better illustrate the problem:

<?php
function error_handler() {
	trigger_error("inside error", E_USER_ERROR);
}
set_error_handler('error_handler');
trigger_error("outside error", E_USER_ERROR);

function exception_handler($exception) {
	throw new Exception('inside exception');
}
set_exception_handler('exception_handler');
throw new Exception('outside exception');
?>
 [2007-10-18 10:39 UTC] gerrit dot boettcher at gmail dot com
Got the same Problem with the ErrorHandler
Just in win32. In Linux this works great.

SourceCode:
-------------------------------------------
--- header.php (Load before any output started or other PHP files loaded)
set_error_handler(array('main','handleError'), E_ALL);

--- main.class.php
final class main {
   [...]
public static function handleError($errorNo, $message, $filename, $lineNo) {
		$errReport = error_reporting();
		
		if ($errReport != 0) {
			if ($errorNo != 8) {
				$type = 'error';
				switch ($errorNo) {
					case 2: $type = 'warning';
					break;
				}
				
				throw new SystemException('PHP '.$type.' in file '.$filename.' ('.$lineNo.'): '.$message, 0);
			}
		}
	}
   [...]
}

--- systemexception.class.php (loaded before main.class.php)
require_once('exceptions/printableexception.class.php');
class SystemException extends Exception implements PrintableException {
[...]
public function show() {
echo '...[...template...]...';
}
[...]
}

--- printableexception.class.php
interface PrintableException {
public function show();
}
----------- EOF --------------

On Linux Systems: anything works great!
On Windows Systems: Exception thrown without a stack frame in Unknown on line 0
 [2007-10-18 11:26 UTC] ceefour at gauldong dot net
You know, "complicated" stack traces like the one you get in Java would be much more helpful than this message. Or the one in Erlang. Or in Ruby with Rails.
 [2007-10-22 08:47 UTC] jani@php.net
See also bug #43016

 [2007-10-22 08:48 UTC] jani@php.net
Does this still happen using latest CVS snapshot/checkout of PHP 5.2 branch?
 [2007-10-30 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-03-25 21:32 UTC] stas@php.net
Maybe related to Bug #51394
 [2010-06-21 01:40 UTC] rjonbone at gmail dot com
This problem is still present as of PHP 5.3.2 on Ubuntu 10.04 using the 
following test cases:

<?php
// Example 1
function exceptionHandlerFunc()
{
	throw new Exception("This message should be visible!");
}

set_exception_handler("exceptionHandlerFunc");

throw new Exception("Something bad happened");
?>
<?php
// Example 2
function shutdownFunc()
{
	throw new Exception("This message should be visible!");
}

register_shutdown_function('shutdownFunc');
?>
<?php
// Example 3
class MyClass
{
	public function __destruct()
	{
		throw new Exception("This message should be visible!");
	}
}

$test = new MyClass();
?>

All result in this error: 'Fatal error: Exception thrown without a stack frame 
in Unknown on line 0'

While I can understand their may be complexities with stack traces, and even 
file and line numbers in these contexts, the original error message should at 
least be visible so that it can be debugged and resolved, i.e. Fatal error: 
Exception (type: Exception, message: 'This message should be visible!') thrown 
without a stack frame in Unknown on line 0.
 [2011-05-17 07:52 UTC] paul at annesley dot cc
This was fixed between PHP 5.3.5 and PHP 5.3.6 in the following revision:

------------------------------------------------------------------------
r307523 | stas | 2011-01-17 08:24:43 +1100 (Mon, 17 Jan 2011) | 2 lines
Fix bug #47143, bug #51458 - provide more useful info in bad exception cases

It didn't seem to make it into the ChangeLog, though.

And it didn't reference this bug.. I guess over the past six years, there's been a 
lot of duplicate reports!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 11:01:27 2024 UTC