Skip to content

catch

In JavaScript, the catch keyword starts the clause of a try statement that runs when the try block throws an exception, and it can bind the thrown value to a name. The clause follows a try block and can be followed by a finally block.

The binding exists only inside the catch block, and it can be a destructuring pattern such as { name, message }. Code can throw any value, so the binding isn’t always an Error object. A statement has only one catch clause, so code checks the error with instanceof and rethrows the errors it doesn’t handle.

Since ES2019, the binding is optional. A catch clause without parentheses runs the same way but ignores the thrown value. The .catch() method of a promise is a regular method that shares the name, not this keyword.

JavaScript catch Keyword Syntax

A catch block follows a try block, with or without a binding:

Language: JavaScript Syntax
try {
  <statements>
} catch (<binding>) {
  <statements>
}

try {
  <statements>
} catch {
  <statements>
}

JavaScript catch Keyword Examples

A catch block receives the error that its try block throws:

Language: JavaScript
> try {
…   null.length;
… } catch (error) {
…   console.log(`${error.name}: ${error.message}`);
… }
TypeError: Cannot read properties of null (reading 'length')
undefined

Reading a property of null throws a TypeError, and the catch block receives it as error.

When the thrown value doesn’t matter, the binding can be left out:

Language: JavaScript
> function isValidJson(text) {
…   try {
…     JSON.parse(text);
…     return true;
…   } catch {
…     return false;
…   }
… }
undefined

> isValidJson("[1, 2]")
true
> isValidJson("[1, 2")
false

JavaScript catch Keyword Use Cases

  • Recovering from an error and continuing with a fallback value
  • Logging or reporting an error before rethrowing it
  • Handling specific error types and rethrowing the rest
  • Turning a thrown error into a return value, such as false from a validity check

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 4, 2026