3 ms·
I think the point is that try/catch in async code is tied to the presence of await. This will run happily without falling into the catch clause: const err
by lhorie 5y ago
I think the point is that try/catch in async code is tied to the presence of await. This will run happily without falling into the catch clause:
const err = async () => {
throw new Error('async error')
}
try {
const rejected = Promise.reject();
const errored = err();
console.log('ok!'); // in real code, this might have returned a deferred to be handled elsewhere instead
} catch (e) {
console.log('not ok!'); // never gets here
}