<?php

class CustomException extends Exception {}

function from() {
    yield 1;
    throw new CustomException();
}

function gen($gen) {
    try {
        yield from $gen;
    } catch (\ClosedGeneratorException $e) {
        yield "Caught ClosedGeneratorException";
    } catch (\Exception $e) {
        yield "Caught Generic Exception";
    }
}

$gen = from();
$gens[] = gen($gen);
$gens[] = gen($gen);

foreach ($gens as $g) {
    $g->current(); // init.
}

foreach ($gens as $i => $g) {
    print "Generator: $i\n";
    print $g->current()."\n";
    $g->next();
}
