Description
Generator::throw() behaves correctly when the exception is caught outside the generator, but if the generator body has its own try/catch around a yield, Elephc aborts with Fatal error: uncaught exception instead of resuming the generator and entering the local catch block.
Steps to reproduce
<?php
function g() {
try {
yield 1;
} catch (Exception $e) {
echo "in,", $e->getMessage();
}
}
$g = g();
$g->current();
$g->throw(new Exception("boom"));
echo ",done";
Expected behavior
PHP 8.4.19 resumes into the generator's catch block and prints:
Actual behavior
Elephc terminates with:
Fatal error: uncaught exception
Additional context
A control case without the in-generator catch works as expected in Elephc:
<?php
function g() { yield 1; }
$g = g();
$g->current();
try {
$g->throw(new Exception("boom"));
} catch (Exception $e) {
echo $e->getMessage();
}
This suggests the bug is specifically in routing the thrown exception back into generator-internal exception handling.
Environment
- Elephc commit:
02ffd63c0efdd8b5dd4069e0b6bd58dfe2a9325d
- PHP:
8.4.19
- OS:
Darwin 25.5.0 arm64
- Reproduced on:
2026-06-04T07:05:57Z
Description
Generator::throw()behaves correctly when the exception is caught outside the generator, but if the generator body has its owntry/catcharound ayield, Elephc aborts withFatal error: uncaught exceptioninstead of resuming the generator and entering the localcatchblock.Steps to reproduce
Expected behavior
PHP 8.4.19 resumes into the generator's
catchblock and prints:Actual behavior
Elephc terminates with:
Additional context
A control case without the in-generator
catchworks as expected in Elephc:This suggests the bug is specifically in routing the thrown exception back into generator-internal exception handling.
Environment
02ffd63c0efdd8b5dd4069e0b6bd58dfe2a9325d8.4.19Darwin 25.5.0 arm642026-06-04T07:05:57Z