Web APIs

AbortSignal.prototype.throwIfAborted()

Try the free JavaScript compiler

Throws the stored reason if aborted, otherwise completes normally. Useful before work begins and at cooperative cancellation checkpoints.

Formal Syntax & Structure

javascript syntaxjavascript
signal.throwIfAborted()

Return Value

undefined

Returns normally when not aborted.

Working Example

Example Snippetjavascript
const c = new AbortController(); c.abort(new Error("canceled"));try { c.signal.throwIfAborted(); } catch (e) { console.log(e.message); }
JavaScript Reference