JavaScript标准内置对象:AggregateError - Web前端
作者:98wpeu发布时间:2026-09-10分类:网页前端技术浏览:8
导读:昨天我们学习了关于“深入了解JavaScript标准内置对象:JSON.stringify()”,今天学习另外一个javascript标准内置对象:AggregateError。A...

昨天我们学习了关于“深入了解JavaScript标准内置对象:JSON.stringify()”,今天学习另外一个javascript标准内置对象:AggregateError。
Aggregateerror,当多个错误需要包装在一个错误中时,该对象表示一个错误。
语法
new AggregateError(errors[, message])
参数
errors错误的描述,默认为空。
message可选AggregateError错误的提示信息。
描述
一个AggregateError当需要由操作报告多个错误被抛出,例如通过Promise.any(),在传递给它的所有promise拒绝。
属性
AggregateError.prototypeAggregateError的原型
AggregateError 实例
实例属性
AggregateError.PRototype.constructor指定创建实例原型的函数。
AggregateError.prototype.message错误消息,默认为
""。AggregateError.prototype.name错误名称,默认为
"AggregateError"。
示例
捕获一个AggregateError
Promise.any([
Promise.reject(new Error("some error")),
]).catch(e => {
console.log(e instanceof AggregateError); // true
console.log(e.message); // "All Promises rejected"
console.log(e.name); // "AggregateError"
console.log(e.errors); // [ Error: "some error" ]
});创建一个AggregateError
try {
throw new AggregateError([
new Error("some error"),
], 'Hello');
} catch (e) {
console.log(e instanceof AggregateError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "AggregateError"
console.log(e.errors); // [ Error: "some error" ]
}
- 上一篇:深入了解JavaScript标准内置对象:JSON.stringify() - Web前端
- 下一篇:已经是最后一篇了
相关推荐
- 深入了解JavaScript标准内置对象:JSON.stringify() - Web前端
- Google:这是造成我们全球范围内严重停电的原因 - Web前端
- Linux Mint新版本:Linux Mint 20.1 Beta发布 - Web前端
- JavaScript标准内置对象:ArrayBuffer - Web前端
- Firefox推出“网络分区”作为一种新的反跟踪防御 - Web前端
- 介绍JS里创建新的异步函数对象:AsyncFunction - Web前端
- 苹果,谷歌,微软和Mozilla禁止哈萨克斯坦的MitM HTTPS证书 - Web前端
- JS内置对象TypeError(类型错误):用来表示值的类型非预期类型时发生的错误 - Web前端
- 了解Microsoft Azure:云服务业务指南 - Web前端
- Google具有新功能和隐私增强功能的Android 11 - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 4【第六章】Foundation之按钮和下拉功能 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery编写widget的一些技巧分享 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 9在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


