Edit report at http://bugs.php.net/bug.php?id=52361&edit=1
ID: 52361
User updated by: hj dot devs at gmail dot com
Reported by: hj dot devs at gmail dot com
Summary: Throwing an exception in a destructor causes invalid
catching
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Linux/Windows
PHP Version: 5.3.2
New Comment:
I'm sorry, correct script is below.
-----------
<?php
class aaa {
public function __destruct() {
try {
throw new Exception(__CLASS__);
} catch(Exception $ex) {
echo "$ex\n";
}
}
}
function bbb() {
$a = new aaa();
throw new Exception(__FUNCTION__);
}
try {
bbb();
echo "must be skipped !!!";
} catch(Exception $ex) {
echo $ex;
}
Previous Comments:
------------------------------------------------------------------------
[2010-07-16 14:10:05] hj dot devs at gmail dot com
Description:
------------
When exceptions are thrown in destructor, PHP5.3.x does not catch any
exceptions
in caller's "try" block.
In addition, destructor's "try" block catches exceptions of caller.
Probably this behavior is bug because it works correctly on PHP5.2.13.
Test script:
---------------
<?php
class aaa {
public function __destruct() {
try {
throw new Exception(__CLASS__);
} catch(Exception $ex) {
}
}
}
function bbb() {
$a = new aaa();
throw new Exception(__FUNCTION__);
}
try {
bbb();
echo "must be skipped !!!";
} catch(Exception $ex) {
echo $ex;
}
Expected result:
----------------
exception 'Exception' with message 'aaa' in example.php:5
Stack trace:
#0 example.php(16): aaa->__destruct()
#1 example.php(16): bbb()
#2 {main}
exception 'Exception' with message 'bbb' in example.php:13
Stack trace:
#0 example.php(16): bbb()
#1 {main}
Actual result:
--------------
exception 'Exception' with message 'bbb' in example.php:13
Stack trace:
#0 example.php(16): bbb()
#1 {main}
Next exception 'Exception' with message 'aaa' in example.php:5
Stack trace:
#0 example.php(16): aaa->__destruct()
#1 example.php(16): bbb()
#2 {main}
must be skipped !!!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52361&edit=1