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;
},

throw被 Internet Explorer 捕获,它似乎阻止了任何其他 javascript 的运行。

在此处输入图像描述

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

4

1 回答 1

1

如果您不想抛出异常,为什么要使用 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;
}
于 2011-09-26T16:04:51.010 回答