Throwing an exception in a destructor causes invalid catching
| Bug #52361 | Throwing an exception in a destructor causes invalid catching | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2010-07-16 14:10 UTC | Modified: | 2010-08-16 11:24 UTC |
|
||||||||||
| From: | hj dot devs at gmail dot com | Assigned: | dmitry (profile) | |||||||||||
| Status: | Closed | Package: | Scripting Engine problem | |||||||||||
| PHP Version: | 5.3.2 | OS: | Linux/Windows | |||||||||||
| Private report: | No | CVE-ID: | None | |||||||||||
[2010-07-16 14:10 UTC] 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 !!!
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2010-07-16 14:12 UTC] hj dot devs at gmail dot com
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; }[2010-08-14 20:45 UTC] Felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
[2010-08-16 11:24 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
[2010-08-16 11:24 UTC] dmitry@php.net