Re:Error Handling in Nodejs
by linkmotif on Friday July 17, 2015 @01:07PM
(#9903728)
FWIW, I think JS swallows all async errors regardless of whether you use .catch(). If the error is thrown async, you can't catch it. Right?
[ Parent
| on HN ]
No. This is the whole point of promises.
Perhaps the gp meant this case?
something().then(function(){
setTimeout(function(){
whoops_not_a_function();
}, 1000);
}).catch(function(){
// nope, nothing to catch
});No built-in help with native promises, but with something like Bluebird you'd prefer:
something().then(() => {
return Promise.delay(1000).then(() => {
whoops_not_a_function();
});
}).catch(() => {
// whoops_not_a_function is not defined
});
...or write Promise_delay yourself on top of native promises (but really just use Bluebird).