如何在回调中正确抛出异常
Q.Promise: How to throw exception in callback correctly?
我这里的简单代码http://jsfiddle.net/xh6960fo/
function test () {
var res = Q.defer();
res.resolve('Hello');
return res.promise;
};
test()
.then(
function(message) {
console.log(message);
throw new Error('Exception!');
},
function (err) {
console.log('no');
console.error(err);
})
.fin(function () {
console.log('fin');
});
我需要在'then'回调中引发异常。
但是在控制台上我只看到
你好鳍
我的异常没有升高。如何正确抛出异常?
then
的异常处理程序只捕获在自己的成功处理程序之前发生的错误,不包括。
...
.then(function() {
throw new Error('error'):
})
.then(null, function(err) {
console.log(err);
})
.fin(...)
相关文章:
- 为什么浏览器没有为语法错误抛出异常
- PHP REST服务抛出异常——希望避免控制台错误
- 测试抛出异常的函数
- (为什么)我不能从生成器中抛出异常吗
- 如何抛出异常
- 抛出异常:Node.js与Gevent
- 当请求DOM对象时,XMLHttpRequest.send()抛出异常
- AngularJS在尝试轻松保存Changes时抛出异常
- $mdDialog.prompt 抛出异常,但该函数在确认时工作正常
- 在 Javascript 中,即使从未抛出异常,使用 try-catch 块是否昂贵
- 自定义抛出异常JavaScript的错误消息
- 在网格弹出编辑器中上传剑道:如何防止上传抛出异常时窗口关闭
- 在原型方法中抛出异常,未在外部尝试捕获 (JavaScript) 中捕获
- 可能从其他域弹出时回调 JavaScript
- XSLT 2.0 错误处理:向 JavaScript 抛出异常
- Bluebird.js:重新抛出catch回调中的错误不会再次被捕获
- 节点样式回调:完成(异常)或抛出异常
- ExtJS 4 - callParent的异步回调抛出异常
- Javascript回调函数抛出错误"回调不是函数"在firefox中
- 如何在回调中正确抛出异常