Recently I've had a very frustrating time debugging a piece of async NodeJS code: an exception that I thought was definitely going to be caught in try..catch
was leaking through, resulting in an unhandled promise error outside of the async_foo
function.
async function async_foo() {
try {
await some_library.async_bar('some illegal argument');
} catch (err) {
console.error(err); // <- Whether this is called depends on async_bar's implementation !
}
}
I've since learned that there are dozens of ways to shoot yourself in the foot in async JS because of how async..await is implemented via Promises, but still:
Is it possible to write your async JS code in a way that will absolutely definitely always handle nested async code's errors, regardless of how the nested async code is implemented? A library-based solution would count.