Bug #69740 [Opn]: finally in generator (yield) swallows exception in iteration
| From: | nikic@php.net | Date: | Mon, 01 Jun 2015 15:35:40 +0000 |
| Subject: | Bug #69740 [Opn]: finally in generator (yield) swallows exception in iteration | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193052@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69740&edit=1
ID: 69740
Updated by: nikic@php.net
Reported by: markus at malkusch dot de
Summary: finally in generator (yield) swallows exception in
iteration
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5.6.9
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Finally handling changed a lot in PHP 5.6, probably some change was not propagated to the generators
implementation.
Previous Comments:
------------------------------------------------------------------------
[2015-06-01 15:30:08] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69740&edit=1