Only Bolivian Here
Only Bolivian Here

Reputation: 36743

Error in Javascript causes page in IE to stop running 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?

Upvotes: 0

Views: 430

Answers (1)

karnyj
karnyj

Reputation: 1222

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

Upvotes: 1

Related Questions