jQuery readyException() Method

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

What Is jQuery.readyException()?

jQuery.readyException(error) (since 3.1) is the hook jQuery calls when a function wrapped in jQuery() / $(document).ready() throws synchronously. By default it re-throws inside setTimeout so the error reaches the console and window.onerror instead of being swallowed.

Remember
// Default behavior (conceptually):
jQuery.readyException = function (error) {
  window.setTimeout(function () {
    throw error;
  });
};

// Official override example:
jQuery.readyException = function (error) {
  console.error(error);
};

// Triggered by:
$(function () {
  throw new Error("Ready handler failed");
});
NeedUse
Register ready code$(fn) / .ready()
Handle sync ready throwsjQuery.readyException = fn
Global uncaught errorswindow.onerror
Local recovery inside readytry { … } catch (e) { … }
Delay ready itselfjQuery.holdReady()

How to Use readyException

Overwrite the hook early, then let ready callbacks throw into it.

  1. Load jQuery 3.1+ (the hook does not exist in older builds).
  2. Assign jQuery.readyException = function (error) { … } before risky ready code.
  3. Register ready callbacks with $(fn) or $(document).ready(fn).
  4. On a sync throw, jQuery calls your hook with the Error.
  5. Log, report, update UI — and optionally setTimeout(function () { throw error; }, 0) to keep default visibility.
PieceRequired?Role
errorYesThe Error thrown inside the ready callback
AssignmentYes (to customize)Replace jQuery.readyException with your function
Default—Async rethrow via setTimeout
Scope—Sync ready throws only

Pseudocode

Pseudocode
register ready callback fn via $(fn) or .ready(fn)

when DOM is ready:
    try:
        call fn()
    catch error:
        call jQuery.readyException(error)

default readyException(error):
    setTimeout → throw error   // console + window.onerror see it

custom readyException(error):
    log / report / update UI
    optionally rethrow in setTimeout

Cheat Sheet

Keep these facts handy when debugging ready-handler failures.

TopicDetail
OverridejQuery.readyException = function (error) { … }
SincejQuery 3.1
TriggerSync throw inside $(fn) / .ready(fn)
DefaultsetTimeout(function () { throw error; })
Official sampleconsole.error(error)
Not coveredAsync errors (timers, promises, later events)
Relatedwindow.onerror, local try/catch

Live Preview

Override readyException, then run a ready callback that throws so you can see the hook fire on the page.

Demo overrides readyException temporarily. Sync throws are simulated via jQuery’s ready path.

Result
Ready — pick an action and click Run.

jQuery Examples

Short, copy-ready snippets. Open DevTools Console for console.error demos, or use Try It Yourself.

Example 1 — Ready Callback Throws

A synchronous throw inside $(fn) is passed to readyException.

jQuery
$(function () {
  throw new Error("Ready handler failed");
});
// Default: rethrown in setTimeout → appears in the console
Try It Yourself

How It Works

  1. Register. $(fn) schedules the callback for DOM ready.
  2. Throw. The callback throws synchronously.
  3. Hook. jQuery calls readyException with that error.
  4. Default. A setTimeout rethrow makes the failure visible.

Example 2 — Official console.error Override

Overwrite the hook to print the error yourself.

jQuery
jQuery.readyException = function (error) {
  console.error(error);
};

$(function () {
  throw new Error("Logged via readyException");
});
Try It Yourself

How It Works

  1. Replace. Assigning a new function overrides the default completely.
  2. Throw. The ready callback fails synchronously.
  3. Log. Your hook receives the error and prints it.
  4. Choice. Skip rethrow if you only want controlled logging.

Example 3 — Show the Error on the Page

Write the message into a status box so you can see the hook without DevTools.

jQuery
jQuery.readyException = function (error) {
  $("#error-box").text(String(error));
};

$(function () {
  throw new Error("Missing config");
});
Try It Yourself

How It Works

  1. Hook. Override readyException before ready runs.
  2. Fail. Ready throws Missing config.
  3. DOM. The hook updates #error-box immediately.
  4. Note. Ready usually runs after enough DOM exists to update UI.

Example 4 — Report, Then Rethrow

Log locally, then keep the default-style async rethrow for window.onerror.

jQuery
jQuery.readyException = function (error) {
  $("#log").text("Reported: " + error.message);
  window.setTimeout(function () {
    throw error;
  }, 0);
};

$(function () {
  throw new Error("Init crashed");
});
Try It Yourself

How It Works

  1. Report. First update your UI or monitoring payload.
  2. Defer. setTimeout(..., 0) matches jQuery’s default idea.
  3. Rethrow. The browser treats it as an uncaught error.
  4. Why. You get both custom handling and normal visibility.

Example 5 — Async Errors Are Not Caught

A throw inside setTimeout never reaches readyException.

jQuery
jQuery.readyException = function (error) {
  $("#log").text("readyException: " + error.message);
};

$(function () {
  $("#log").text("Ready ran. Scheduling async throw…");
  setTimeout(function () {
    throw new Error("Too late for readyException");
  }, 0);
});
Try It Yourself

How It Works

  1. Ready succeeds. The callback itself does not throw.
  2. Later. setTimeout throws on a future turn.
  3. Miss. That throw is outside jQuery’s ready try/catch.
  4. Handle elsewhere. Use local catch, promise handlers, or window.onerror.

Edge Cases & Pitfalls

Check these before relying on readyException in production.

sync

Only synchronous throws

Timers, promises, and later event handlers never call this hook.

override

Replacing the default hides console noise

If you only console.error and never rethrow, there is no uncaught exception for window.onerror.

version

Needs jQuery 3.1+

Older builds do not expose jQuery.readyException — check your version first.

order

Assign the hook before ready runs

If ready already fired and threw, a late override cannot catch that past error.

Browser Support

jQuery.readyException has been part of jQuery since 3.1. It works wherever your loaded jQuery 3.1+ build runs.

✓ Stable · jQuery 3.1+

jQuery.readyException()

Available in modern jQuery 3.x builds. Prefer a current 3.7+ release. Not present on jQuery 1.x / 2.x.

100% jQuery 3.1+
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
readyException jQuery 3.1+

Bottom line: Safe on jQuery 3.1+. Override early, keep sync-only expectations clear, and rethrow when you still want console visibility.

Performance Notes

ApproachCostBest for
Default async rethrowCheapKeeping bugs visible
Light custom log / UICheapDemos and local diagnostics
Heavy work inside the hookExpensiveAvoid — report briefly, then continue

The hook runs only when a ready callback fails. Keep it tiny: log, enqueue a report, optionally rethrow — do not rebuild the page there.

Key Takeaways

  • Role: catches sync throws from $(fn) / .ready().
  • Default: rethrows in setTimeout so errors stay visible.
  • Override: jQuery.readyException = function (error) { … }.
  • Limit: async failures need other tools — not this hook.

One line: jQuery.readyException is the 3.1+ hook for sync ready failures — customize logging, but remember async errors bypass it.

Frequently Asked Questions

jQuery.readyException(error) runs when a function wrapped in jQuery() or jQuery(document).ready() throws synchronously. By default it re-throws the error inside a setTimeout so the console and window.onerror still see it instead of the error being swallowed.
It was added in jQuery 3.1. Older jQuery versions do not expose this hook.
Overwrite the function: jQuery.readyException = function(error) { console.error(error); }; You can log, report to a service, update UI, or also rethrow with setTimeout to keep default visibility.
No. It only handles errors thrown synchronously while the ready callback runs. Errors inside setTimeout, promises, or later event handlers are not passed to readyException.
Re-throwing on a later turn of the event loop keeps jQuery’s ready system from swallowing the exception and lets the browser’s normal error reporting (console + window.onerror) run.
Callbacks registered with $(fn), $(document).ready(fn), and equivalent ready entry points. See the .ready() and jQuery() tutorials for how ready itself works.

Next: jQuery Selectors

Move on from core ready hooks to selecting elements with jQuery.

Selectors hub →

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