I have recently been reading about async/await and using try and catch to handle promise rejections, and have been applying it to some of my old code.
I have the following:
async function() {
try {
await Promise.all([some functions]);
doIfNoError();
} catch (error) {
console.log(error);
}
The functions I am passing to Promise.all follow the form:
async function() {
some code
if (some condition) {
return true
} else {
throw false
}
}
I intend that if any of the functions passed into Promise.all reject, the rejection is displayed. If none of the functions reject, then doIfNoError should fire. However, doIfNoError sometimes fires when it shouldn't, and I am given the error "Unhandled Promise Rejection".
doIfNoError
function is doing some job that throws an error. Could you please add a real example here ? – Raj KumarPromise.all
, not the functions themselves. – Bergitry
/catch
code is fine, it must be either the calls or the contents of theasync function
s. – Bergiawait Promise.all([some functions])
should beawait Promise.all([some promises]);
– Mulan