node.js - NodeJS is swallowing my exception thrown from a callback -
assume following code:
mymodule.dostuff(options, function(err, results) { if (err) console.log('e', err); if (err) throw err; console.log(results); });
the offending code is:
return new promise(function(resolve, reject) { try { throw new error('test error'); resolve('success'); } catch (ex) { console.log('r', ex); reject(ex); } });
and farther chain:
self.adapter .collect(self.options) .then(function(data) { self.callback(null, data); if (self.runnable) { settimeout(self.collect.bind(self), 2000); } }, function(error) { self.callback(error); });
the 'e [error info here]' statement prints, throw statement apparently ignored. app happily continues doing whatever else instructed , not crash expected. why?
i never found answer specific library using, after switching q library, exposed crucial step may have been missing before also. if there no reject handler @ top level of promise chain, exception may swallowed. according q documentation, way around call .done()
@ top of chain flushes pending exceptions caller.
Comments
Post a Comment