Re:Error Handling in Node.js
by morghus on Friday November 04, 2016 @06:15AM
(#12871463)
Can anyone explain why this pattern doesn't work? Or point me to some resource?
[ Parent
| on HN ]
Try/catch is not async and exceptions do not bubble up through the async context, which makes sense as the caller moved on with execution. Try this in your console:
try {
console.log("see, ");
setTimeout(() => {throw new Error("oops")}, 100);
console.log(
"I can't assume here that"
+ " the prev. line succeeded"
);
} catch(e) {
console.log("error!");
}There's a footnote about this:
https://www.joyent.com/node-js/production/design/errors#fn:1