【发布时间】:2015-06-22 23:23:40
【问题描述】:
有人可以向我解释为什么我的第一个示例中没有抛出我的错误吗?当我使用process.nextTick() 时为什么会这样?
var deferred = require('deferred');
// This code does not work.
// Error seems to never been thrown and script kind of freeze without saying anything.
deferred.resolve().then(function(){
console.log('deferred resolved');
throw new Error('Synchronous error thrown in deferred.then()');
});
// This code does work.
// I just embedded the throw in the process.nextTick() method.
deferred.resolve().then(function(){
console.log('deferred resolved');
process.nextTick(function(){
throw new Error('Synchronous error thrown in deferred.then()');
});
});
为什么我需要等待 nextTick 在then() 内抛出错误...
任何解释将不胜感激。 谢谢
我看过这篇文章 (No errors thrown/displayed when in a deferred callback)。但它只给出了一半的答案......
【问题讨论】:
标签: node.js exception-handling deferred