Running the code
Promise.all(new Promise((res, rej) => rej('Failure!')))
.catch(() => console.log("It's all okay."))
in Node v12.19.0 logs It's all okay.
to the console but still throws an exception. Why is that? I would have expected the same behaviour as when I run
new Promise((res, rej) => rej('Failure!'))
.catch(() => console.log("It's all okay."))
This will also log It's all okay.
to the console but does not throw an exception.
How can I catch the rejection in Promise.all()?
Full console output:
> Promise.all(new Promise((res, rej) => rej('Failure!'))).catch(() => console.log("It's all okay."))
Promise { <pending> }
> It's all okay.
(node:2872) UnhandledPromiseRejectionWarning: Failure!
(node:2872) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
> new Promise((res, rej) => rej('Failure!')).catch(() => console.log("It's all okay."))
Promise { <pending> }
> It's all okay.