From:             felixcca at yahoo dot ca
Operating system: Irrelevant
PHP version:      5.2.8
PHP Bug Type:     Scripting Engine problem
Bug description:  Throwing an exception in a destructor causes a fatal error

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 bug report at http://bugs.php.net/?id=47143&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=47143&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=47143&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=47143&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=47143&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47143&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=47143&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=47143&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=47143&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=47143&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=47143&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=47143&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=47143&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=47143&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=47143&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=47143&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=47143&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=47143&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=47143&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=47143&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=47143&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=47143&r=mysqlcfg

Reply via email to