jQuery Deferred catch() Method

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is catch()?

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.

Remember
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)
NeedUse
Handle rejection (modern)dfd.catch(fn)
Handle rejection (classic)dfd.fail(fn)
Success pathdfd.then(fn)
Cleanup either waydfd.always(fn)

How to Use catch()

Build a then/catch chain, then settle the Deferred.

  1. Create a Deferred (or use a jqXHR from $.get / $.ajax).
  2. Chain .then(successFn) for the happy path.
  3. Add .catch(failFn) for rejections and thrown errors.
  4. Settle with resolve() / reject() (or wait for AJAX).
PieceRequired?Role
Deferred / PromiseYesObject that may reject
failFilterYesFunction called on rejection
Return—Promise (chainable)

Pseudocode

Pseudocode
catch(fn):
  return then(null, fn)   // official alias

on reject(reason) OR throw in then():
  call failFilter(reason)
  if failFilter returns value:
    next then() can continue (recovered)
  if failFilter throws / returns rejected:
    chain stays rejected

Cheat Sheet

Keep these facts handy for Deferred error handling.

TopicDetail
Syntaxdeferred.catch( failFilter )
Aliasdeferred.then( null, failFilter )
Runs whenRejected (or throw / rejected promise in chain)
Success?Skipped
ReturnsPromise
vs fail()Same idea; catch is promise-style (3.0+)
SincejQuery 3.0

Live Preview

Compare reject, success skip, thrown errors, and multi-step propagation.

Browser demo of deferred.catch — same ideas as the examples below.

Result
catch: Network timeout

jQuery Examples

Short, copy-ready snippets (jQuery 3+). Open DevTools Console, or use Try It Yourself for a live editor.

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.
  4. Catch runs. Prints the rejection reason.

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.
  4. Try reject. Use the Try-it lab to flip to a failure path.

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.
  4. Catch receives the Error. Message is logged.

Example 4 — AJAX-Style Error Message

Simulate a failed request and show a user-friendly message in catch().

jQuery
function fetchItems() {
  var dfd = $.Deferred();

  setTimeout(function () {
    dfd.reject("Server unavailable (503)");
  }, 200);

  return dfd
    .then(function (items) {
      console.log("Loaded:", items.join(", "));
    })
    .catch(function (error) {
      console.log("Could not load items — " + error);
    });
}

fetchItems();
Try It Yourself

How It Works

  1. Simulate AJAX. A timer rejects with a status message.
  2. Then is for success. Skipped on reject.
  3. Catch shows UI text. User-friendly error string.
  4. Real jqXHR. Same pattern works on $.get(...).then(...).catch(...).

Example 5 — Single catch() for a Multi-Step Chain

Place one error handler at the end; rejections from any step bubble to it.

jQuery
function stepOne() {
  return $.Deferred().resolve(10).promise();
}

function stepTwo(value) {
  return $.Deferred().resolve(value * 2).promise();
}

function stepThree(value) {
  return $.Deferred().reject("Step 3 failed at " + value).promise();
}

stepOne()
  .then(stepTwo)
  .then(stepThree)
  .then(function (final) {
    console.log("success:", final);
  })
  .catch(function (error) {
    console.log("catch:", error);
  });
Try It Yourself

How It Works

  1. Step 1. Resolves with 10.
  2. Step 2. Doubles to 20.
  3. Step 3. Rejects with a message including 20.
  4. Final then skipped. One terminal catch() handles the pipeline.

Edge Cases & Pitfalls

Check these before relying on catch() in chains.

version

Missing on jQuery 1.x / 2.x

catch is jQuery 3.0+. Older code must use fail() or then(null, fn).

success

Skipped on resolve

A successful chain never enters catch(). Put success work in then() / done().

recover

Returning a value recovers

If catch returns a normal value, later then() handlers can run again — intentional recovery.

order

Place catch after the steps you care about

A catch in the middle can swallow an error so later steps still run. Terminal catch is usually clearer.

always

Not a substitute for always()

Catch is error-only. Spinner hide / unlock still belongs in always().

Browser Support

deferred.catch() is part of jQuery’s Deferred API (since 3.0). It works in any browser where jQuery 3.x runs. For jQuery 1.x/2.x, use fail() or then(null, fn).

✓ jQuery 3.0+ · Browsers

jQuery deferred.catch()

Supported in jQuery 3.x across Chrome, Firefox, Safari, Edge, and other browsers with jQuery 3 loaded. Not available in jQuery 1.x / 2.x.

100% With jQuery 3+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
deferred.catch() jQuery 3+

Bottom line: Use catch() on jQuery 3+. On older projects, prefer fail() — same rejection idea, different method name.

Performance Notes

OperationCostBest for
catch(fn)O(1) registerAttaching one rejection handler
Reject + catchO(n) handlersRunning fail filters in order
Per-step catchMore queuesPrefer one terminal catch unless recovering mid-chain

Registering catch() is cheap. Prefer one terminal catch for a pipeline unless you intentionally recover mid-chain. Keep handlers light — log, map to a user message, or return a fallback value.

Key Takeaways

  • Role: handle rejections in a promise-style Deferred chain.
  • Alias: catch(fn) ≡ then(null, fn).
  • Throws: errors inside then() also land in catch().
  • Version: jQuery 3.0+; older code uses fail().

One line: catch() is the modern Deferred rejection hook — same idea as native Promise catch.

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()

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

$.Deferred() tutorial →

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