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
Fundamentals
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.
Concept
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.
Foundation
📝 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.
readyException receives Error: Ready handler failed
Default implementation schedules a rethrow
DevTools shows an uncaught error shortly after
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" );
});
console.error shows the Error object
No automatic setTimeout rethrow (unless you add one)
Matches the official documentation sample
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.
console.warn runs first
Then an uncaught error appears (setTimeout throw)
Mirrors the spirit of jQuery's default implementation
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 );
});
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
readyException3.1+
Bottom line: Use it to control how sync ready-handler failures are reported.
Wrap Up
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().
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about readyException
The ready-callback error hook since jQuery 3.1.
5
Core concepts
!01
Sync
Throws
Ready
⏱02
Default
Rethrow
Timeout
✎03
Override
Allowed
Hook
≠04
Not
Async
Limit
3.105
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.