Edit report at http://bugs.php.net/bug.php?id=47143&edit=1
ID: 47143 Updated by: s...@php.net Reported by: felixcca at yahoo dot ca Summary: Throwing an exception in a destructor causes a fatal error -Status: Open +Status: Closed Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: * PHP Version: 5.2.8 -Assigned To: +Assigned To: stas Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-01-16 22:24:45] s...@php.net Automatic comment from SVN on behalf of stas Revision: http://svn.php.net/viewvc/?view=revision&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=47143&edit=1