aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/aggregateerror
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/aggregateerror
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/aggregateerror')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/aggregateerror/index.html106
1 files changed, 106 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/aggregateerror/index.html b/files/zh-cn/web/javascript/reference/global_objects/aggregateerror/index.html
new file mode 100644
index 0000000000..ddc0486653
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/aggregateerror/index.html
@@ -0,0 +1,106 @@
+---
+title: AggregateError
+slug: Web/JavaScript/Reference/Global_Objects/AggregateError
+translation_of: Web/JavaScript/Reference/Global_Objects/AggregateError
+---
+<blockquote>
+<p>{{JSRef}}{{Draft}}{{SeeCompatTable}}</p>
+</blockquote>
+
+<p><code><strong>AggregateError</strong></code><font><font>当多个错误​​需要包装在一个错误中时,</font><font>该</font><font>对象表示一个错误。</font></font></p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox notranslate">new AggregateError(errors[, message])</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>errors</code></dt>
+ <dd>错误的描述,默认为空。</dd>
+ <dt><code>message</code>{{Optional_Inline}}</dt>
+ <dd>AggregateError错误的提示信息。</dd>
+</dl>
+
+<h2 id="描述"><font><font>描述</font></font></h2>
+
+<p><font><font>一个</font></font><code>AggregateError</code><font><font>当需要由操作报告多个错误被抛出,例如通过</font></font><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise/any"><code>Promise.any()</code></a><font><font>,在传递给它的所有</font></font><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise/any"><code>Promise</code></a><font><font>拒绝。</font></font></p>
+
+<h2 id="属性">属性</h2>
+
+<dl>
+ <dt><code>AggregateError.prototype</code></dt>
+ <dd><code>AggregateError</code><font><font>的原</font></font><font><font>型</font></font></dd>
+</dl>
+
+<h2 id="AggregateError_实例">AggregateError 实例</h2>
+
+<h3 id="实例属性">实例属性</h3>
+
+<dl>
+ <dt><code>AggregateError.prototype.constructor</code></dt>
+ <dd>指定创建实例原型的函数。</dd>
+ <dt>{{JSxRef("Error.prototype.message", "AggregateError.prototype.message")}}</dt>
+ <dd><font><font>错误消息,默认为</font></font><code>""</code><font><font>。</font></font></dd>
+ <dt>{{JSxRef("Error.prototype.name", "AggregateError.prototype.name")}}</dt>
+ <dd><font><font>错误名称,默认为</font></font><code>"AggregateError"</code><font><font>。</font></font></dd>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="捕获一个AggregateError"><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="background-color: #333333;">捕获一个</span></font>AggregateError</h3>
+
+<pre class="brush: js; notranslate">Promise.any([
+ Promise.reject(new Error("some error")),
+]).catch(e =&gt; {
+ 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" ]
+});
+</pre>
+
+<h3 id="创建一个AggregateError">创建一个AggregateError</h3>
+
+<pre class="brush: js; notranslate">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" ]
+}
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td><a href="https://tc39.es/proposal-promise-any/#sec-aggregate-error-constructor">ESNext Promise.any Proposal</a></td>
+ <td><span class="spec-Draft">Stage 3 Draft</span></td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+
+
+<p>{{Compat("javascript.builtins.AggregateError")}}</p>
+</div>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li>{{JSxRef("Error")}}</li>
+</ul>