jQuery readyException() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Core

Definition

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.

Syntax

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

jQuery
// 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");
});
CallWhat it does
errorThe Error thrown inside the ready callback
AssignmentReplace jQuery.readyException with your function
DefaultAsync rethrow via setTimeout
ScopeSync ready throws only

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

Parameters

ParameterDescription
Step 1Load jQuery 3.1+ (the hook does not exist in older builds).
Step 2Assign jQuery.readyException = function (error) { … } before risky ready code.
Step 3Register ready callbacks with $(fn) or $(document).ready(fn).

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

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.

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.

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.

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: noConflict() Method

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

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

6 people found this page helpful