ES6——Generator函数抛出异常

function* gen(x){
    try {
        var y = yield x + 2; } catch (e){
             console.log(e);
             console.log("进入异常catch输出");
    }
    return y; 
}
var g = gen(1);
console.log(g.next());
g.throw('出错了');

原文地址:https://www.cnblogs.com/sunupo/p/15477420.html