JavaScript标准内置对象:AggregateError - Web前端
作者:98wpeu发布时间:2026-09-10分类:网页前端技术浏览:112
导读:昨天我们学习了关于“深入了解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" ]
}
相关推荐
- 网络掉链子,没网或网不好,微信咋连服务器? - Web前端
- 手机“内存”被榨干,微信没资格启动 - Web前端
- 小程序怎么实现登录时获取用户手机号? - Web前端
- 微信登录时怎么获取用户信息?这些关键细节你得懂 - Web前端
- 微信小程序:先搞懂登录+用户信息的底层逻辑 - Web前端
- unknown cookie是什么?会影响浏览安全吗? - Web前端
- 先搞懂Page和Component是干啥的? - Web前端
- 开发网页端SVG编辑器要解决哪些核心问题? - Web前端
- 缩进结束后,cursor自动关闭,不用手动写close - Web前端
- 询问 SEO:最常见的 Hreflang 错误是什么以及如何审核它们? - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 4【第六章】Foundation之按钮和下拉功能 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 7jQuery编写widget的一些技巧分享 - 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属性


