I have two promises, one rejected and other resolved. Promise.all is called. It executed the catch block of Promise.all as one of the promises is rejected.
c
A catch
on a Promise acts the same as a try {} catch {}
block, in that you have captured the error state and the program will continue to function as normal.
That's why, when you omit the catch
, your promise state is "rejected"
.
If, after having caught the error, you want to return the promise state as rejected you need to return a rejected promise from the catch handler:
const promise3 = Promise.all([promise1, promise2])
.catch(error => {
console.log("REJECTED", error);
return Promise.reject(error);
});
console.log(promise3); // [[PromiseStatus]]: "rejected"
Similar to doing a throw
inside a try {} catch { throw; }
block