Bug #32101 [Com]: Exception in unknown on line 0 when throwing exception inside exception handler

2011-05-16 Thread paul at annesley dot cc
Edit report at http://bugs.php.net/bug.php?id=32101edit=1

 ID: 32101
 Comment by: paul at annesley dot cc
 Reported by:ceefour at gauldong dot net
 Summary:Exception in unknown on line 0 when throwing
 exception inside exception handler
 Status: No Feedback
 Type:   Bug
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:5CVS-2005-02-15
 Block user comment: N
 Private report: N

 New Comment:

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!


Previous Comments:

[2010-06-21 01:40:02] 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.


[2010-03-25 21:32:30] s...@php.net

Maybe related to Bug #51394


[2007-10-30 01:00:01] 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.


[2007-10-22 08:48:40] j...@php.net

Does this still happen using latest CVS snapshot/checkout of PHP 5.2
branch?


[2007-10-22 08:47:25] j...@php.net

See also bug #43016






The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

http://bugs.php.net/bug.php?id=32101


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


Req #47143 [Com]: Throwing an exception in a destructor causes a fatal error

2011-05-16 Thread paul at annesley dot cc
Edit report at http://bugs.php.net/bug.php?id=47143edit=1

 ID: 47143
 Comment by: paul at annesley dot cc
 Reported by:felixcca at yahoo dot ca
 Summary:Throwing an exception in a destructor causes a fatal
 error
 Status: Closed
 Type:   Feature/Change Request
 Package:*General Issues
 Operating System:   *
 PHP Version:5.2.8
 Assigned To:stas
 Block user comment: N
 Private report: N

 New Comment:

More specifically, 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.


Previous Comments:

[2011-01-16 22:26:17] s...@php.net

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




[2011-01-16 22:24:45] s...@php.net

Automatic comment from SVN on behalf of stas
Revision: http://svn.php.net/viewvc/?view=revisionamp;revision=307523
Log: Fix bug #47143, bug #51458 - provide more useful info in bad
exception cases


[2009-01-18 08:26:28] felixcca at yahoo dot ca

Sorry, made a mistake on the original error message. It's Exception 

thrown without a stack frame, as stated below, and not Exception 

thrown without a stack trace.


[2009-01-18 05:16:31] felixcca at yahoo dot ca

Description:

Basically a duplicate of #31304, but it seems I can't reopen the ticket


myself since I'm not a dev nor the original poster.



When an exception is thrown in a destructor, the exception is lost, and


a pointless Fatal Error is issued:

Fatal Error: Exception thrown without a stack trace



debug_backtrace() will still get you a stack trace from a destructor 

without issuing any error, let alone causing the loss of debugging data.


Also, only wrapping the exception in a try-catch inside the destructor 

works, and allows you to just print the exception and exit as if 

exceptions really worked in destructors.



Why spit out the Fatal Error?

Reproduce code:
---
?php

class ExceptionThrower

{

public function __destruct()

{

throw new Exception;

}

}

$obj = new ExceptionThrower;

?



Expected result:

Fatal error: Uncaught exception 'Exception' in snippet.php:6

Stack trace:

#0 [internal function]: ExceptionThrower-__destruct()

#1 {main}

  thrown in snippet.php on line 6











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






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


Bug #51458 [Com]: Lack of error context with nested exceptions

2011-05-16 Thread paul at annesley dot cc
Edit report at http://bugs.php.net/bug.php?id=51458edit=1

 ID: 51458
 Comment by: paul at annesley dot cc
 Reported by:nlgordon at gmail dot com
 Summary:Lack of error context with nested exceptions
 Status: Closed
 Type:   Bug
 Package:Unknown/Other Function
 Operating System:   Redhat Linux
 PHP Version:5.3.2
 Assigned To:stas
 Block user comment: N
 Private report: N

 New Comment:

More specifically, 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.


Previous Comments:

[2011-01-16 22:26:38] s...@php.net

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




[2011-01-16 22:24:47] s...@php.net

Automatic comment from SVN on behalf of stas
Revision: http://svn.php.net/viewvc/?view=revisionamp;revision=307523
Log: Fix bug #47143, bug #51458 - provide more useful info in bad
exception cases


[2011-01-09 22:37:32] sailormax at inbox dot lv

same problem with 5.2.x after 5.2.5;

I had calling unexist function in exception handler. In result PHP
returned empty page and didn't write any error in logs. Not very
comfortable debug scripts in such conditions... :/


[2010-04-01 23:15:54] nlgordon at gmail dot com

Description:

In short, if you thrown an exception from within the exception handler,
you get an uninformative error message with no contextual information. 
It makes sense for this case to be a fatal error.  We don't want to get
recursive throwing of exceptions and spiral to our death.



If you create an exception in the error handler without throwing it, it
has the correct info about where it was created. This is enough to
figure out where the error is coming from.  It is at least far more
informative and gives you a starting place in a potentially complex code
base.



From my quick look at the code in Zend/zend_exceptions.c:94 where this
originates.  It looks like the exception is there, and that would have
file/line num info.

Test script:
---
?php



set_exception_handler(exceptionHandler);



function exceptionHandler($excp)

{

throw new Exception(Error 2);

}



throw new Exception(Error 1);

Expected result:

Fatal Error: Error 2

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






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