<?php function yieldFromIteratorGeneratorThrows() { try { yield from new class(new ArrayIterator([1, -2])) extends IteratorIterator { public function key() { if ($k = parent::key()) { throw new Exception; } return $k; } }; } catch (Exception $e) { yield 2; } } foreach (yieldFromIteratorGeneratorThrows() as $k => $v) { var_dump($v); }
You have javascript disabled. You will not be able to edit any code.