JSFiddle - React, Tailwind, and code Playground

by Gajus Kuizinas

JavaScript

var generatorFunction,
    iterator,
 
generatorFunction = function * () {
    while (true) {
        try {
            yield;
        } catch (e) {
            if (e != 'a') {
                throw e;
            }
            console.log('Generator caught', e);
        }
    }
};
 
iterator = generatorFunction();
 
iterator.next();
 
try {
    iterator.throw('a');
    iterator.throw('b');
} catch (e) {
    console.log('Uncaught', e);
}
 
// Generator caught a
// Uncaught b