I have read several articles on this subject, but it is still not clear to me if there is a difference between Promise.reject
vs. throwing an error.(我已经阅读了几篇关于这个主题的文章,但我仍然不清楚Promise.reject
与抛出错误之间是否存在差异。)
return asyncIsPermitted()
.then(function(result) {
if (result === true) {
return true;
}
else {
return Promise.reject(new PermissionDenied());
}
});
Using throw(用投掷)
return asyncIsPermitted()
.then(function(result) {
if (result === true) {
return true;
}
else {
throw new PermissionDenied();
}
});
My preference is to use throw
simply because it is shorter, but was wondering if there is any advantage of one over the other.(我倾向于使用throw
只是因为它更短,但是想知道是否有一个优于另一个。)
ask by Naresh translate from so