Example 1 — Return a Stack String
The classic use: return new Error().stack and read it in exceptionHook.
jQuery.Deferred.getStackHook = function () {
return new Error().stack; // a string
};
jQuery.Deferred.exceptionHook = function (error, asyncError) {
console.log(error.message); // "boom"
console.log(typeof asyncError); // "string"
};
$.Deferred().resolve().then(function () {
throw new Error("boom");
}); How It Works
- Define.
getStackHookreturns a stack string when a callback is queued. - Throw. The
.then()callback throws an error. - Receive.
exceptionHookgets the saved string asasyncError.

