Bug Tracker

Modify

Ticket #5840 (closed bug: worksforme)

Opened 3 years ago

Last modified 2 years ago

ajax callbacks lose exceptions

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

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

comment:1 Changed 3 years ago by snover

  • Status changed from new to closed
  • Resolution set to worksforme

 test case works for me.

comment:2 Changed 2 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..

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.