| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw | [Back] [Original] |
Get to know MDN better
generatorInstance.throw(exception)
2 Object
exception try...catch throw()
throw() throw exception; exception throw() throw(exception) yield try...catch
throw try...catch
function* gen() {
while (true) {
try {
yield 42;
} catch (e) {
console.log("Error caught!");
}
}
}
const g = gen();
g.next();
// { value: 42, done: false }
g.throw(new Error("Something went wrong"));
// "Error caught!"
// { value: 42, done: false }
| ECMAScript 2027 LanguageSpecification # sec-generator.prototype.throw |
| Web Proxy Viewer | New URL | Original Page |