|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 !!!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 18:00:01 2025 UTC |
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; }