Why jQuery 3.0 Hides Errors and How to Catch Them with Promises

This article explains why errors thrown inside a jQuery 3.0 ready handler are silently ignored, compares the behavior with jQuery 2.x, and shows how to use the new Promise‑based $.ready() API with fail() to surface those errors in the console.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Why jQuery 3.0 Hides Errors and How to Catch Them with Promises

jQuery introduced a major change in version 3.0: the ready handler now returns a Promise. If you simply write

$(function(){ throw new Error('出错了'); $('#container').html('你好'); })

, the error is swallowed and the page shows no content, while the console remains silent.

In contrast, using jQuery 2.1.3 the same code triggers a visible error in the console, making debugging easier.

Because jQuery 3.0 officially supports Promise , you can handle errors by chaining $.ready().then(...).fail(...). For example:

$.ready().then(function() {
    throw new Error('出错了');
    $('#container').html('你好');
}).fail(function(error) {
    throw error;
});

Now the console correctly displays the error message.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaScriptError HandlingPromisejQuery
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.