Bug #73337 [NEW]: try/catch not working with two exceptions inside a same operation
| From: | bwoebi@php.net | Date: | Tue, 18 Oct 2016 10:27:04 +0000 |
| Subject: | Bug #73337 [NEW]: try/catch not working with two exceptions inside a same operation | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-204889@lists.php.net to get a copy of this message | ||
From: bwoebi
Operating system: Irrelevant
PHP version: 7.1.0RC3
Package: Scripting Engine problem
Bug Type: Bug
Bug description:try/catch not working with two exceptions inside a same operation
Description:
------------
If two exceptions happen to be thrown inside a same opcode (the last one
of both *must* be thrown from within a separate function, e.g. an
userland destructor).
The bug is in zend_throw_exception_internal(). We do not overwrite
EG(opline_before_exception) in case the current opcode is
ZEND_HANDLE_EXCEPTION.
This is problematic in the case we aren't yet at that opcode, but it
just got set to it by a previous call to
zend_throw_exception_internal(). I.e. in case one exception has been
triggered and then another exception is thrown within the same opcode.
This leads to throw_op_num (= EG(opline_before_exception) -
EX(func)->op_array.opcodes) inside ZEND_HANDLE_EXCEPTION opcode being
bogus and catching does not work thus.
Test script:
---------------
class d { function __destruct() { throw new Error; } }
try { new d + new d; } catch (Error $e) { print "Exception properly
caught"; }
Expected result:
----------------
Exception properly caught
Actual result:
--------------
Fatal error: Uncaught Error in Command line code:1
Stack trace:
#0 Command line code(1): d->__destruct()
#1 {main}
Next Error in Command line code:1
Stack trace:
#0 Command line code(1): d->__destruct()
#1 {main}
thrown in Command line code on line 1
--
Edit bug report at https://bugs.php.net/bug.php?id=73337&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73337&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73337&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73337&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73337&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73337&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73337&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73337&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73337&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73337&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73337&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73337&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73337&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73337&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73337&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73337&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73337&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73337&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73337&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73337&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73337&r=mysqlcfg