jQuery.Deferred.exceptionHook()


jQuery.Deferred.exceptionHook()Returns: Error

Description: Handle errors produced by Deferreds.

This API is called every time an error is thrown inside Deferreds. By default, it only warns about errors that are more likely to be programmer errors than errors thrown due to application logic. This includes errors like SyntaxError or ReferenceError.

The function accepts two parameters - the first one is the error thrown and the second, optional parameter is a "fake" error created before the handler is called so that a stack trace from before an async barrier is available. This second error is only provided if jQuery.Deferred.getErrorHook is defined; see the docs for that API for more details.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// These usually indicate a programmer mistake during development;
// warn about them ASAP rather than swallowing them by default.
var rerrorNames = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;
// If `jQuery.Deferred.getErrorHook` is defined, `asyncError` is an error
// captured before the async barrier to get the original error cause
// which may otherwise be hidden.
jQuery.Deferred.exceptionHook = function( error, asyncError ) {
if ( error && rerrorNames.test( error.name ) ) {
MyLoggingLibrary.log(
"jQuery.Deferred exception",
error,
asyncError
);
}
};