Standard built-ins

AsyncGenerator.prototype.throw()

Try the free JavaScript compiler

Queues an exception at the suspension point and returns a promise, which rejects if the error is unhandled.

Formal Syntax & Structure

javascript syntaxjavascript
asyncGenerator.throw([value])

Parameters & Attributes

NameTypeDescription
valueanyOptional resumption, completion or error value.

Return Value

Promise<IteratorResult>

Promise for the iteration result.

Working Example

Example Snippetjavascript
async function* g(){try{yield 1;}catch(e){yield e.message;}}(async()=>{const i=g();await i.next();console.log((await i.throw(new Error("x"))).value);})();
JavaScript Reference