<?php
class CustomException extends Exception {}
function from() {
yield 1;
throw new CustomException();
}
function gen($gen) {
yield from $gen;
}
$gen = from();
$gens[] = gen($gen);
$gens[] = gen($gen);
foreach ($gens as $g) {
}
foreach ($gens as $i => $g) {
print "Generator: $i\n";
try {
} catch (\ClosedGeneratorException $e) {
print "Caught ClosedGeneratorException\n";
} catch (\Exception $e) {
print "Caught Generic Exception\n";
}
}
PD9waHAKCmNsYXNzIEN1c3RvbUV4Y2VwdGlvbiBleHRlbmRzIEV4Y2VwdGlvbiB7fQoKZnVuY3Rpb24gZnJvbSgpIHsKICAgIHlpZWxkIDE7CiAgICB0aHJvdyBuZXcgQ3VzdG9tRXhjZXB0aW9uKCk7Cn0KCmZ1bmN0aW9uIGdlbigkZ2VuKSB7CiAgICB5aWVsZCBmcm9tICRnZW47Cn0KCiRnZW4gPSBmcm9tKCk7CiRnZW5zW10gPSBnZW4oJGdlbik7CiRnZW5zW10gPSBnZW4oJGdlbik7Cgpmb3JlYWNoICgkZ2VucyBhcyAkZykgewogICAgJGctPmN1cnJlbnQoKTsgLy8gaW5pdC4KfQoKZm9yZWFjaCAoJGdlbnMgYXMgJGkgPT4gJGcpIHsKICAgIHByaW50ICJHZW5lcmF0b3I6ICRpXG4iOwogICAgdHJ5IHsKICAgICAgICAkZy0+Y3VycmVudCgpOwogICAgICAgICRnLT5uZXh0KCk7CiAgICB9IGNhdGNoIChcQ2xvc2VkR2VuZXJhdG9yRXhjZXB0aW9uICRlKSB7CiAgICAgICAgcHJpbnQgIkNhdWdodCBDbG9zZWRHZW5lcmF0b3JFeGNlcHRpb25cbiI7CiAgICB9IGNhdGNoIChcRXhjZXB0aW9uICRlKSB7CiAgICAgICAgcHJpbnQgIkNhdWdodCBHZW5lcmljIEV4Y2VwdGlvblxuIjsKICAgIH0KfQo=