jQuery .readyException() Method

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

What You’ll Learn

jQuery.readyException() is the hook jQuery calls when a ready callback throws. This tutorial explains the default setTimeout rethrow, how to override it for logging, what it does not catch, and five practical examples with try-it labs.

01

Hook

Ready errors

02

Default

setTimeout

03

Override

console.error

04

Sync

Only

05

$(fn)

ready

06

3.1+

Since

Introduction

Almost every jQuery page starts with $(function() { … }) or $(document).ready(…). If that function throws, you still want a clear error in the console — not a silent failure that leaves the UI half initialized.

Since jQuery 3.1, jQuery routes those synchronous exceptions through jQuery.readyException(error). The default implementation re-throws inside a timeout so DevTools and window.onerror still report the bug.

You can replace jQuery.readyException with your own function to log to a service, show a friendly message, or call console.error without rethrowing. Pair this topic with .ready() and jQuery.ready for the full ready lifecycle.

Understanding the jQuery.readyException() Method

When a callback registered via jQuery(fn) / jQuery(document).ready(fn) throws synchronously, jQuery catches the error and invokes jQuery.readyException(error) with that Error object.

The stock implementation schedules a rethrow so the exception is not eaten by jQuery’s internal try/catch. Overwrite the method if your app needs different handling — the official docs show piping to console.error.

💡
Beginner Tip

Assign your override before registering ready handlers that might throw, otherwise the first error still uses the previous handler.

📝 Syntax

Signature (jQuery 3.1+):

jQuery
jQuery.readyException( error )

Parameters

  • error — the Error (or throw value) from the ready callback.

Return value

  • Not used by application code in practice — jQuery calls this hook for side effects (logging / rethrow).
  • You overwrite the function; you rarely call it yourself.

Official override pattern

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

⚡ Quick Reference

GoalCode
Default behaviorBuilt-in: rethrow via setTimeout
Log without rethrowjQuery.readyException = function(e){ console.error(e); };
Report + rethrowLog, then setTimeout(function(){ throw e; }, 0)
Trigger the hook$(function(){ throw new Error("boom"); });
Not coveredAsync errors inside ready (promises, timers)

📋 readyException vs window.onerror vs try/catch

Three layers of error handling — pick the right scope.

readyException
ready only

Sync throws inside $(fn) / .ready() — jQuery 3.1+ hook

window.onerror
global

Browser-wide uncaught errors (including default rethrows)

try/catch
local

Wrap risky code inside your ready callback yourself

.ready()
register

Schedules the callback that may throw into readyException

Examples Gallery

Examples follow the official jQuery API and common production overrides. Use Try It Yourself to see console and on-page logging.

📚 Getting Started

See the hook fire and the official console.error override.

Example 1 — Ready Callback Throws (Default Hook)

A synchronous throw inside $(function(){…}) is passed to readyException.

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

How It Works

jQuery wraps ready callbacks so a sync throw does not abort its internal queue silently. The default hook restores visibility by rethrowing asynchronously.

Example 2 — Official: Log With console.error

Overwrite jQuery.readyException to print the error without relying on the default rethrow.

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

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

How It Works

Assigning a new function replaces the default completely. Prefer this when you want controlled logging and do not need an uncaught exception afterward.

📈 Practical Patterns

Custom reporting and understanding sync vs async limits.

Example 3 — Show Errors in the Page UI

Write the message into a banner so beginners can see the hook without opening DevTools.

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

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

How It Works

Because the hook runs immediately when the ready callback throws, the DOM is usually already interactive enough to update a status element.

Example 4 — Report Then Keep Default Rethrow

Log locally, then rethrow asynchronously so window.onerror still fires.

jQuery
jQuery.readyException = function( error ) {
  // sendToMonitor( error ); // your APM / analytics
  console.warn( "readyException:", error );
  setTimeout( function() {
    throw error;
  }, 0 );
};
Try It Yourself

How It Works

This hybrid keeps observability (your logger) while preserving browser default reporting. Avoid infinite loops: do not throw again from inside a synchronous path that re-enters the same hook unexpectedly.

Example 5 — Async Errors Are Not Passed to readyException

A throw inside setTimeout during ready does not call the hook.

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

$(function() {
  setTimeout( function() {
    throw new Error( "Too late for readyException" );
  }, 0 );
});
Try It Yourself

How It Works

The ready wrapper only surrounds the synchronous body of your callback. Deferred work needs its own error handling.

🚀 Common Use Cases

  • Central logging — send ready failures to Sentry, LogRocket, or your API.
  • Friendlier demos — show on-page error text instead of only the console.
  • Hardening apps — keep default rethrow so bugs stay visible in QA.
  • Debugging init — distinguish ready-time throws from later click/Ajax errors.
  • Teaching — explain why a broken $(function(){…}) still surfaces in DevTools.

🧠 How readyException Fits Ready

1

Register a ready callback

$(fn) or $(document).ready(fn) queues your function.

Ready
2

Callback throws synchronously

jQuery’s wrapper catches the exception during invocation.

Throw
3

Call jQuery.readyException

Your override or the default timeout rethrow runs.

Hook
4

Visible failure

Console, onerror, or your logger records the bug.

📝 Notes

  • Added in jQuery 3.1.
  • Only synchronous throws in ready wrappers are handled.
  • Default implementation rethrows via setTimeout so errors are not swallowed.
  • Overwrite before registering risky ready handlers.
  • Not a substitute for try/catch around async work or promise rejections.
  • Related DOM APIs: .ready(), jQuery.ready, jQuery.holdReady().

Browser Support

jQuery.readyException is available in jQuery 3.1+ (including 3.7.x). It is a jQuery core hook — any browser that can run your jQuery build supports overriding it. There is no separate browser polyfill.

jQuery 3.1+

jQuery.readyException()

Works wherever jQuery 3.1+ runs. Override freely in modern evergreen browsers. Pair with window.onerror or reporting SDKs for full coverage.

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

Bottom line: Use it to control how sync ready-handler failures are reported.

Conclusion

jQuery.readyException() is the dedicated error hook for synchronous failures inside ready callbacks. Keep the default rethrow for visibility, or override it to log and report without hiding bugs.

Next up: binding modern event handlers with .on().

💡 Best Practices

✅ Do

  • Set a custom readyException early in your bootstrap file
  • Log the full Error (message + stack) to your monitor
  • Keep a rethrow or console.error so failures stay visible
  • Use try/catch or promise .catch for async init
  • Learn .ready() alongside this hook

❌ Don’t

  • Swallow errors with an empty readyException body
  • Expect it to catch timer/promise failures automatically
  • Assume it exists on jQuery < 3.1
  • Confuse it with window.onerror (broader scope)
  • Forget that default behavior exists to protect debuggability

Key Takeaways

Knowledge Unlocked

Five things to remember about readyException

The ready-callback error hook since jQuery 3.1.

5
Core concepts
02

Default

Rethrow

Timeout
03

Override

Allowed

Hook
04

Not

Async

Limit
3.1 05

Since

jQuery 3.1

API

❓ 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 browser 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 — ready-handler errors were harder to customize.
Overwrite the function: jQuery.readyException = function(error) { console.error(error); }; You can send the error to a logging service, show a fallback UI, or keep the default timeout rethrow.
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 in a new turn of the event loop keeps the ready system from swallowing the exception and lets the browser’s normal error reporting (console + window.onerror) run. A plain catch without rethrow would hide bugs.
Yes. It applies to callbacks registered with $(fn), $(document).ready(fn), and equivalent ready entry points. See the DOM tutorials for .ready() and jQuery.ready for how ready itself works.
Did you know?

Before jQuery 3.1 there was no documented public hook specifically for ready-callback exceptions. The addition of jQuery.readyException made it possible to plug in application-level reporting without forking jQuery’s ready implementation — while the default setTimeout rethrow kept console visibility for everyday debugging.

Next: jQuery .on() Method

Bind event handlers with the modern API — direct and delegated.

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