[php-src] Issue #8269: Exceptions thrown during yield operation fall through the generator instead of being handled within

From: Date: Tue, 29 Mar 2022 11:33:20 +0000
Subject: [php-src] Issue #8269: Exceptions thrown during yield operation fall through the generator instead of being handled within
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240553@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8269
Author: bwoebi

### Description

The following code:

```php
<?php

set_error_handler(function() { throw new \Error(); });

function &gen() {
    try {
        yield 1;
    } catch (Error $e) {
        print "Caught";
    }
}

foreach (gen() as $y);
```

Resulted in Uncaught Error

But I expected this output instead:
```
Caught
```

I wouldn't change the longstanding behaviour in current PHP versions, but should be fixed for
PHP 8.2 possibly, for academical correctness at least.

### PHP Version

master

### Operating System

_No response_


Thread (1 message)

  • bwoebi
« previous php.bugs (#240553) next »