Standard built-ins
Generator.prototype.throw()
Injects an exception into the generator at its suspended position. A catch may handle it; otherwise it propagates.
Formal Syntax & Structure
javascript syntaxjavascript
generator.throw([value])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| value | any | Input or completion/exception value; optional. |
Return Value
object
Iterator result object.
Working Example
Example Snippetjavascript
function* g(){try{yield 1;}catch(e){yield e.message;}}const i=g();i.next();console.log(i.throw(new Error("x")).value);