jQuery Deferred catch() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Error handling

What You’ll Learn

The catch() method attaches an error handler to a jQuery Deferred or promise chain. It runs when the operation is rejected or when a then() callback throws — giving you a familiar, Promise-style way to centralize failure handling.

01

Syntax

dfd.catch(fn)

02

On reject

Handles failures

03

vs fail()

Same behavior

04

Chain

then → catch

05

Throws

Catches exceptions

06

jQuery 3+

Promises/A+ API

Introduction

Async code fails — networks drop, APIs return errors, and validation throws. Without a dedicated error path, failures either crash your script or leave users staring at a broken UI. jQuery’s Deferred API gives you fail() for rejections; since jQuery 3.0, catch() offers the same behavior with Promise-style naming.

Use catch() at the end of a chain (or after any then()) to log errors, show messages, retry requests, or fall back to cached data — all in one readable place instead of scattering checks everywhere.

Understanding the catch() Method

catch() is part of jQuery’s Promises/A+ compatible Deferred interface (jQuery 3.0+). When you call deferred.catch(errorHandler), jQuery queues your function and invokes it when:

  • The Deferred is rejected via reject() or rejectWith().
  • A then() callback throws an exception.
  • A then() callback returns a rejected promise or Deferred.

The handler receives the rejection reason — often a string, Error object, or AJAX error details. It does not run when the chain resolves successfully.

💡
Beginner Tip

If you know native JavaScript Promise.catch(), jQuery’s version works the same way on Deferred chains. On jQuery 3+, catch() and fail() are interchangeable.

📝 Syntax

General form of deferred.catch:

jQuery
deferred.catch( errorHandler [, errorHandler ] )

Parameters

  • errorHandler — function executed when the Deferred is rejected or when an upstream then() fails. Receives the rejection reason as argument(s). You may register multiple handlers.

Return value

  • Returns the same Deferred/promise object for chaining further then() or catch() calls.

Promise-style chain

jQuery
myAsyncTask()
  .then(function (result) {
    return processResult(result);
  })
  .catch(function (error) {
    console.error("An error occurred:", error);
  });

⚡ Quick Reference

GoalCode
Handle rejectiondfd.catch(fn)
Legacy jQuery namedfd.fail(fn) (same as catch)
Success pathdfd.then(fn) or dfd.done(fn)
Cleanup either waydfd.always(fn)
Minimum jQuery3.0+ for catch()

📋 catch() vs fail() vs always()

Pick the handler that matches the outcome you need to respond to.

catch()
on reject

Promise-style errors

fail()
on reject

jQuery 1.5+ alias

always()
on either

Shared cleanup

then()
on resolve

Success + transform

Examples Gallery

Each example uses jQuery 3.7+ Deferred APIs. Use DevTools or the Try-it links to run them interactively.

📚 Getting Started

Handle a simple rejection with catch().

Example 1 — Handle a Rejected Deferred

Register catch() before calling reject() with an error message.

jQuery
const dfd = $.Deferred();

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

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

How It Works

reject() moves the Deferred to a failed state. Any registered catch() (or fail()) handlers run with the rejection reason.

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

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

jQuery
function loadProfile() {
  const dfd = $.Deferred();

  setTimeout(function () {
    dfd.resolve({ name: "Alex" });
  }, 200);

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

How It Works

On success, then() runs and catch() is skipped. Change the call to dfd.reject("404") and only catch() executes — that is the pattern from the original reference example, expanded for clarity.

📈 Practical Patterns

Real-world error paths in multi-step async chains.

Example 3 — Catch Exceptions Inside then()

Throwing in a then() callback converts the failure into 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.error("catch:", err.message);
  });
Try It Yourself

How It Works

Even though the Deferred initially resolved, the thrown Error inside then() propagates down the chain — just like native Promises — and triggers catch().

Example 4 — AJAX-Style Error Message

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

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

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

  return dfd
    .then(function (items) {
      $("#list").text(items.join(", "));
    })
    .catch(function (error) {
      $("#list").text("Could not load items — " + error);
    });
}
Try It Yourself

How It Works

With real $.ajax(), you would attach the same catch() to the jqXHR promise. One handler covers network errors, HTTP failures, and parse errors passed through the chain.

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

Place one error handler at the end; rejections from any intermediate step bubble down 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.error("catch:", error);
  });
Try It Yourself

How It Works

Steps one and two succeed; step three rejects. The final then() is skipped and catch() receives the rejection — centralizing error handling for the whole pipeline.

🚀 Use Cases

  • Promise chains — attach one catch() after several then() steps to handle any failure in the pipeline.
  • AJAX requests — show error toasts or fallback UI when $.ajax() rejects.
  • Chained Deferreds — keep error logic consistent when each step returns a new promise.
  • Validation errors — throw inside then() and let catch() format the message for users.
  • Logging — record structured error context in one place before optional recovery.

🧠 How catch() Handles Failures

1

Chain runs

then() callbacks execute on success. catch() waits in the queue.

Pending
2

Failure occurs

A step rejects, throws, or returns a rejected promise — the chain enters failed state.

Reject
3

catch() runs

Registered handlers receive the reason. Downstream then() success handlers are skipped.

Handle
=

Graceful recovery

Users see helpful feedback instead of silent failures — or the chain recovers if catch returns a value.

📝 Notes

  • catch() requires jQuery 3.0+. On older versions, use fail().
  • catch is a reserved word in older ES5 strict contexts — jQuery still exposes it as a method name on objects.
  • Returning a plain value from catch() can resume the chain with a resolved promise.
  • Pair with always() when you also need cleanup on success.
  • For brand-new code without jQuery, native Promise.catch() follows the same mental model.

Browser Support

deferred.catch() is available in jQuery 3.0+ as part of Promises/A+ compatibility. It works wherever that jQuery version runs.

jQuery 3.0+

jQuery Deferred.catch()

Supported in jQuery 3.x across all browsers jQuery supports. Not available in jQuery 1.x or 2.x — use fail() instead.

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

Bottom line: Load jQuery 3.7+ for modern promise-style chains. Legacy projects on jQuery 2.x should keep using fail().

🎉 Conclusion

The deferred.catch() method gives you a clean, Promise-style way to handle failures in jQuery async chains. Centralize error messages, logging, and fallbacks in one callback instead of duplicating checks after every step.

Practice the five examples above, then explore jQuery.Deferred() to see how Deferred objects are created and wired into your own APIs.

💡 Best Practices

✅ Do

  • Attach one catch() at the end of long chains
  • Log contextual error details for debugging
  • Show user-friendly messages in the UI
  • Test both reject and throw paths
  • Use fail() when supporting jQuery < 3

❌ Don’t

  • Swallow errors with empty catch handlers
  • Put success logic inside catch()
  • Assume catch() runs on resolve
  • Forget to propagate errors you cannot recover from
  • Mix unhandled throws outside the promise chain

Key Takeaways

Knowledge Unlocked

Five things to remember about catch()

Reliable error handling for jQuery async chains.

5
Core concepts
02

Reject only

Not on success

Scope
= 03

fail()

Same behavior

Alias
🔗 04

Propagates

Chain-wide

Pattern
3+ 05

jQuery 3

Promises/A+

Version

❓ Frequently Asked Questions

catch() registers a callback that runs when the Deferred is rejected or when an earlier then() callback throws an error or returns a rejected promise. It is the promise-style counterpart to fail().
In jQuery 3.0+, catch() is an alias for fail() on Deferred and Promise objects. They behave the same — catch() exists so jQuery chains look like native Promise code.
No. catch() runs only when the chain is rejected. Successful resolution skips catch() and continues to the next then() handler.
catch() was added in jQuery 3.0 as part of Promises/A+ compatibility. Use fail() if you must support jQuery 1.x or 2.x.
Yes. If your catch handler returns a normal value or resolves a new Deferred, the chain can continue with then(). If catch re-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, like hiding spinners.
Did you know?

jQuery added catch() in version 3.0 so Deferred chains could mirror native Promise syntax — but under the hood it still uses the same rejection machinery as the original fail() method from jQuery 1.5.

Continue to jQuery.Deferred()

Learn how to construct Deferred objects from scratch.

jQuery.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.

6 people found this page helpful