I am struggling with promises
having the following snippet:
Promise.resolve()
.then(a("OK1"))
.then(a("OK2"))
.then(a("OK3"))
.then(a("OK4"))
.then(a("OK5"))
.then(function() {
console.log("FINISH");
})
.catch(function(e) {
console.log("ERROR: " + e);
});
function a(i) {
return new Promise(function(resolve, reject) {
if(i == "OK4") {
console.log("THROW");
throw('Error'); //This does not happen
reject();
return;
}
if(i == "OK2") {
reject()
return;
}
console.log(i);
resolve();
});
}
i want to be able to reject a promise - then the next .then
is executed ("OK3")
but i am unable to throw exceptions - i want to trigger the .catch on "OK4"
OK4 - is rejected and not outputted, but OK5 still gets executed - is there a way arround it?
this would be my expected output:
OK1
OK3
ERROR: ....