I've read this article about the fact that jQuery deferreds are not Promise/A+ compliant
Which leads me to test a code (which should raise error without propagating to main window and stop running , they suggested similar code , but I wanted to try and make it simplier - hence my question):
var def = new jQuery.Deferred();
var bar = def.then(function (rslv) {
try {
throw Error('Exception!');
}
catch (e) {
def.reject();
}
return def.promise();
});
bar.fail(function (val) { //why doesn't this line run ?
console.log('Exception thrown and handled');
});
def.resolve();
console.log(1)
Question:
def.then(...)
returns a promise which is kept in bar
bar
- when failed - should run :
bar.fail(function (val) {
console.log('Exception thrown and handled');
});
But it is not running.
What am I missing?