Bug Tracker

Opened 8 years ago

Closed 7 years ago

Last modified 6 years ago

#5840 closed bug (worksforme)

ajax callbacks lose exceptions

Reported by: borgar Owned by:
Priority: critical Milestone: 1.4.1
Component: ajax Version: 1.4
Keywords: Cc:
Blocked by: Blocking:

Description

The following code should throw an error ("DOES_NOT_EXIST is not defined"), but doesn't in Firefox:

$.ajax({
  success: function(html){
    DOES_NOT_EXIST++;
  }
});

This is not a case of jQuery swallowing the error in a try/catch but rather that Firefox seems to loose the error somewhere in it's event handling.

While I think this is a browser bug, I think it needs addressing in jQuery because of the debugging implications: This may hide 1.4 compatibility errors in callbacks from developers upgrading.

Apart from try/catch within the callback itself, the only way I've been able to keep the exception is to defer it with a timeout:

function success() {
  // If a local callback was specified, fire it and pass it the data
  if ( s.success ) {
    try {
      s.success.call( callbackContext, data, status, xhr );
    } catch (e) {
      setTimeout(function(){
        throw e;
      },0);
    }
  }
  // ...

Change History (2)

comment:1 Changed 7 years ago by snover

Resolution: worksforme
Status: newclosed

test case works for me.

comment:2 Changed 6 years ago by paul

I had the same problem; starting Firefox 4 in safe mode solved the problem. Turned out to be the Adblock Plus extension that was swallowing the errors in my case..

Note: See TracTickets for help on using tickets.