async function thisThrows() {
return new Promise((resove, reject) => {
throw new Error("Thrown from thisThrows()");
});
}
async function thatThrows() {
return new Promise(async(resolve, reject) => {
try {
await thisThrows();
} catch (err) {
throw err;
}
console.log('reached here');
resolve(true);
});
}
async function run() {
try {
await thatThrows();
} catch (e) {
console.error('catch error', e);
} finally {
console.log('We do cleanup here');
}
}
run();
I have situation where i don't want the statement console.log('reached here'); resolve(true); should execute if error in thrown by previous statements. I tried several combinations but no luck. run method should catch the error. In my above code run method catch method not executed