jQuery Deferred catch() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Deferred

Definition

deferred.catch(failFilter) adds a handler that runs when the Deferred is rejected (since jQuery 3.0). Officially it is an alias for deferred.then(null, fn) and returns a Promise. Use it for promise-style error handling, just like native Promise.catch.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
dfd.catch(fn)  ≡  dfd.then(null, fn)

// Official AJAX-style pattern:
$.get("test.php")
  .then(function () { /* success */ })
  .catch(function () { /* failed */ });

// Older equivalent:
dfd.fail(fn)
CallWhat it does
Deferred / PromiseObject that may reject
failFilterFunction called on rejection
ReturnPromise (chainable)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Create a Deferred (or use a jqXHR from $.get / $.ajax).
Step 2Chain .then(successFn) for the happy path.
Step 3Add .catch(failFn) for rejections and thrown errors.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Handle a Rejected Deferred

Register catch(), then reject() with an error message.

jQuery
var dfd = $.Deferred();

dfd.catch(function (error) {
  console.log("catch:", error);
});

dfd.reject("Network timeout");
Try It Yourself

How It Works

  1. Create. Deferred starts pending.
  2. Register catch. Handler waits for rejection.
  3. Reject. State becomes rejected with the reason string.

Example 2 — Classic then() / catch() Chain

Process success in then(); route failures to catch().

jQuery
var dfd = $.Deferred();

dfd
  .then(function (result) {
    console.log("Profile:", result.name);
  })
  .catch(function (error) {
    console.log("Failed:", error);
  });

dfd.resolve({ name: "Alex" });
// → Profile: Alex
// (catch skipped)
Try It Yourself

How It Works

  1. Chain then + catch. Success and error paths.
  2. Resolve with data. Happy path runs.
  3. Catch skipped. No rejection occurred.

Example 3 — Catch Exceptions Inside then()

Throwing in a then() callback becomes a rejection that catch() handles.

jQuery
$.Deferred()
  .resolve({ id: 0 })
  .then(function (data) {
    if (!data.id) {
      throw new Error("Invalid user id");
    }
    console.log("Valid id:", data.id);
  })
  .catch(function (err) {
    console.log("catch:", err.message);
  });
Try It Yourself

How It Works

  1. Resolve first. Data arrives successfully.
  2. Validate in then. id is falsy → throw.
  3. Throw becomes reject. Same idea as native Promises.

Frequently Asked Questions

catch(failFilter) adds a handler that runs when the Deferred is rejected. Officially, deferred.catch(fn) is an alias for deferred.then(null, fn). It returns a Promise.
They both handle rejections. catch() was added in jQuery 3.0 as a Promises/A+-style name and is an alias of then(null, fn). fail() is the classic Deferred API available earlier. Prefer catch() in modern then()-style chains.
No. Successful resolution skips catch(). Only reject, a thrown error in then(), or a rejected promise in the chain triggers it.
catch() was added in jQuery 3.0. On jQuery 1.x or 2.x, use fail() or then(null, fn) instead.
Yes. If the catch handler returns a normal value (or a resolved Deferred), later then() handlers can continue. If it throws or returns a rejected promise, the chain stays rejected.
Use catch() (or fail()) for error-specific logic — messages, retries, fallbacks. Use always() for shared cleanup that runs on both success and failure.

Next: deferred.done() Method

Learn how to create Deferred objects and control resolve, reject, and progress.

deferred.done() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful