Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Promise.prototype.catch — handling rejection

The catch() method attaches a promise rejection handler. It lets you recover with a successful value or propagate a failure and, with the standard then method, returns a new promise.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

promise.catch(onRejected)

Promise.prototype.catch calls this.then(undefined, onRejected). With the standard then, it returns a new promise without changing the original promise's state. The onRejected handler receives the rejection reason, which need not be an Error object, and runs asynchronously even if the promise was already rejected.

Returning an ordinary value from the handler fulfills the new promise with that value; omitting return produces undefined. Returning a promise or an object with a callable then adopts its eventual outcome. Throwing an error rejects the new promise. To propagate a failure, use throw rather than merely logging it.

Fulfillment skips the handler and passes the value through. If onRejected is not a function, rejection also passes through. A catch placed after then also handles errors thrown in that earlier step, but not errors in later steps or in independent asynchronous operations that were not returned.

Examples

Promise.resolve(10)
  .then(() => {
    throw new Error("failed");
  })
  .catch((error) => {
    console.log(error.message);
    return 42;
  })
  .then((value) => {
    console.log(value);
  });
console.log("sync");

Result

sync
failed
42

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources