finally in generator (yield) swallows exception in iteration
| Bug #69740 | finally in generator (yield) swallows exception in iteration | ||||
|---|---|---|---|---|---|
| Submitted: | 2015-06-01 15:30 UTC | Modified: | 2015-06-01 15:35 UTC | ||
| From: | markus at malkusch dot de | Assigned: | nikic (profile) | ||
| Status: | Closed | Package: | Scripting Engine problem | ||
| PHP Version: | 5.6.9 | OS: | Linux | ||
| Private report: | No | CVE-ID: | None | ||
[2015-06-01 15:30 UTC] markus at malkusch dot de
Description: ------------ From https://wiki.php.net/rfc/generators I learned that finally blocks are valid in Generators: > If the generator contains (relevant) finally blocks those will be run. When I iterate over such a generator and would throw an exception the exception seems to be swallowed. This behaviour was introduced in PHP-5.6 as it worked in PHP-5.5 as I would expect it: http://3v4l.org/QX4qP I can't tell if this is related to https://bugs.php.net/bug.php?id=62210. Test script: --------------- <?php function generate() { try { yield 1; yield 2; } finally { echo "finally\n"; } } foreach (generate() as $i) { echo $i, "\n"; throw new Exception(); } Expected result: ---------------- 1 finally Fatal error: Uncaught exception 'Exception' Actual result: -------------- 1 finally
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2015-06-01 15:35 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
[2015-06-01 15:35 UTC] nikic@php.net
[2015-06-11 15:45 UTC] nikic@php.net
-Status: Assigned +Status: Closed