function *genTestError() {
    while (true) {
        try {
            var val = yield null;
            console.log('value', val);
        } catch (e) {
            console.log('There was an error', e);
        }
    }
}

var test = genTestError();
test.next();
// Invoke the error by throwing it
test.throw(new Error('test error'));
// logs There was an error Error: test error