Q诺从未引用过

Kris Kowal的Q文档指出, Q.onerror是在未处理的exception时调用的。
我不能使它工作:

 var Q = require('q'); Q.longStackSupport = true; var util = require('util'); Q.onerror=function(){ console.log('Q.onerror::') console.log(util.inspect(arguments)) } function get(){ var def=Q.defer(); def.resolve('resolved'); return def.promise; } get() .then(function(val){ console.log('ok:'+val) undefined._prop; // i would expect this exception to be // forwarded to Q.onerror... but it doesn't console.log('not reachd') }); 

输出:

 ok:resolved 

我想我不太了解Q.onerror的使用我想跟踪一个不错的堆栈跟踪未处理的exception(也可能是拒绝)

Q现在不跟踪*未处理的拒绝,所以你必须明确告诉它链已经结束。

Q.onerror处理在已done子句中未处理的exception:

 get() .done(function(val){ // you can not chain this, this indicates the chain is done console.log('ok:'+val) undefined._prop; // i would expect this exception to be // forwarded to Q.onerror... but it doesn't console.log('not reachd') }); 

这与Bluebird这样的库不同,它可以自己计算出未处理的拒绝,或者使用GC来检测未处理的拒绝。

*(atm,一个实验性的function被添加到Q然后删除)