<?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) {
    $g->current(); // init.
}

foreach ($gens as $i => $g) {
    print "Generator: $i\n";
    try {
        $g->current();
        $g->next();
    } catch (\ClosedGeneratorException $e) {
        print "Caught ClosedGeneratorException\n";
    } catch (\Exception $e) {
        print "Caught Generic Exception\n";
    }
}
