Javascript 错误导致 IE 中的页面停止运行 javascript

发布于 2024-12-05 11:47:20 字数 788 浏览 4 评论 0原文

在我的网站上,我引用了一个 javascript 文件,在 IE 上,抛出此错误:

send: function (data) {
    /// <summary>Sends data over the connection</summary>
    /// <param name="data" type="String">The data to send over the connection</param>
    /// <returns type="signalR" />
    var connection = this;

    if (!connection.transport) {
        // Connection hasn't been started yet
        throw "SignalR: Connection must be started before data can be sent. Call .start() before .send()";
    }

    connection.transport.send(connection, data);

    return connection;
},

Internet Explorer 正在捕获该 throw,并且它似乎会停止任何其他 javascript 的运行。

在此处输入图像描述

我该怎么做才能使错误不会完全停止页面上的所有内容?

On my website, I have a reference to a javascript file, and on IE, this error is thrown:

send: function (data) {
    /// <summary>Sends data over the connection</summary>
    /// <param name="data" type="String">The data to send over the connection</param>
    /// <returns type="signalR" />
    var connection = this;

    if (!connection.transport) {
        // Connection hasn't been started yet
        throw "SignalR: Connection must be started before data can be sent. Call .start() before .send()";
    }

    connection.transport.send(connection, data);

    return connection;
},

That throw is being caught by Internet Explorer, and it appears to halt any other javascript from running.

enter image description here

What can I do so that error doesn't completely halt everything on my page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失与倦" 2024-12-12 11:47:20

如果你不想抛出异常,为什么还要使用 throw 呢?
如果您希望出于日志记录目的而例外,请考虑这一点:

if (!connection.transport) {
    // Connection hasn't been started yet
    setTimeout(function() {
        throw "SignalR: Connection must be started before data can be sent. Call .start() before .send()"; 
    }, 0);
    return;
}

Why are you using throw if you don't want to throw the exception?
consider this, if you want the exception for logging purposes:

if (!connection.transport) {
    // Connection hasn't been started yet
    setTimeout(function() {
        throw "SignalR: Connection must be started before data can be sent. Call .start() before .send()"; 
    }, 0);
    return;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文