Please, look at the following code. Line 5: return ex
.
When I call myFunc
, I expect to see 'err'
in the console, but I see 'yes'
which means that outside of myFunc
the error is not being captured. The error is not bubbling up.
Which makes sense because I'm not rethrowing the error doing: throw ex
or using Promise.reject(ex)
.
My Question is: How to ensure the error is captured outside of my function without using the two methods mentioned above? Is there a way?
async function myFunc() {
try {
throw new Error();
} catch (ex) {
return ex;
}
}
myFunc().then(() => console.log('yes')).catch(() => console.log('err'))
// 'yes'