Ticket #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: | ||
| 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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

test case works for me.