Favorites

JavaScript throw Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
throw
JavaScript Control FlowThis statement is supported by all modern browsers.
Updated 28th November 2026

The throw statement raises an exception, stopping the current function and passing control to the nearest catch block.

Description

The throw statement throws a user-defined exception. Execution of the current function stops, and control passes to the first catch block in the call stack; if there is none, the script reports an uncaught error. You can throw any value, but throwing an Error (or a subclass) gives a stack trace and a consistent message.

Inside an async function, throw rejects the returned promise.

Throwing stops execution immediately, so code after the throw in the same block never runs. Throw errors for situations the current function genuinely can't handle, such as invalid arguments, and let calling code decide how to recover. Custom error classes that extend Error make it easy to tell different problems apart with instanceof, and the cause option keeps the original error when you rethrow a more meaningful one.

Syntax

throw expression;

Example

function divide(a, b) {
  if (b === 0) throw new RangeError('Cannot divide by zero');
  return a / b;
}
try {
  console.log(divide(10, 2));
  console.log(divide(1, 0));
} catch (err) {
  console.log(err.name + ': ' + err.message);
}

Browser Support

The following information will show you the current browser support for the throw statement. Hover over a browser icon to see the version that first introduced support for this statement.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee