我在执行以下代码时收到未捕获的异常。当我尝试创建自动拒绝的诺言时,它会失败。
如果我在拒绝承诺前设置了一个小的超时时间,它就会起作用。
function emptyPromise(fail) {
return new Promise(function (resolve, reject) {
if (fail) {
reject({
status: -20,
responseText: {
reason: 'Empty promise',
success: false
}
});
} else {
resolve();
}
});
}
var arr = [emptyPromise(true)];
Promise.all(arr).then(function(){}).catch(function(e){console.log(e);})
答案 0 :(得分:0)
我刚刚找到了一个解决方案,即使选中“在异常情况下暂停”,该解决方案也不会在chrome开发工具中引发异常。
function emptyPromise(fail) {
return Promise.reject('rere');
}
emptyPromise(true).catch(function(){console.log(arguments)})
这个static promise reject method为我节省了很多。 创建空承诺时,请使用Promise.resolve(...)和Promise.reject(...)进行设置。