aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/webassembly/runtimeerror/index.html
blob: 7d0598d250ea2831423c6923ba9e19aa0201f170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: WebAssembly.RuntimeError()
slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError
translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError
---
<div>{{JSRef}}</div>

<p><code><strong>WebAssembly.RuntimeError()</strong></code>构造函数创建一个新的WebAssembly RuntimeError对象---一个每当WebAssembly陷入指定陷阱时将抛出的类型。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">new WebAssembly.RuntimeError(<var>message</var>, <var>fileName</var>, <var>lineNumber</var>)</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><code>message</code> {{optional_inline}}</dt>
 <dd>有可读性的错误信息。</dd>
 <dt><code>fileName</code> {{optional_inline}}{{non-standard_inline}}</dt>
 <dd>包含导致异常的代码的文件名。</dd>
 <dt><code>lineNumber</code> {{optional_inline}}{{non-standard_inline}}</dt>
 <dd>导致异常的代码的行号。</dd>
</dl>

<h2 id="属性">属性</h2>

<p><em><code>RuntimeError</code>构造函数不包含其自身特有的属性,但是,它确实通过原型链继承了某些属性。</em></p>

<dl>
 <dt><code>WebAssembly.RuntimeError.prototype.constructor</code></dt>
 <dd>创建示例原型的特定函数。</dd>
 <dt>{{jsxref("Error.prototype.message", "WebAssembly.RuntimeError.prototype.message")}}</dt>
 <dd>错误信息。 尽管ECMA-262指定{{jsxref("URIError")}}应提供自己的<code>message</code>属性,但在<a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a>中,它继承了{{jsxref("Error.prototype.message")}}</dd>
 <dt>{{jsxref("Error.prototype.name", "WebAssembly.RuntimeError.prototype.name")}}</dt>
 <dd>错误名称。继承自 {{jsxref("Error")}}.</dd>
 <dt>{{jsxref("Error.prototype.fileName", "WebAssembly.RuntimeError.prototype.fileName")}}</dt>
 <dd>报出错误的文件路径。继承自 {{jsxref("Error")}}.</dd>
 <dt>{{jsxref("Error.prototype.lineNumber", "WebAssembly.RuntimeError.prototype.lineNumber")}}</dt>
 <dd>报出错误的代码所在文件中的行数。继承自{{jsxref("Error")}}.</dd>
 <dt>{{jsxref("Error.prototype.columnNumber", "WebAssembly.RuntimeError.prototype.columnNumber")}}</dt>
 <dd>报出错误的代码所在文件中的列数。继承自 {{jsxref("Error")}}.</dd>
 <dt>{{jsxref("Error.prototype.stack", "WebAssembly.RuntimeError.prototype.stack")}}</dt>
 <dd>堆栈跟踪。 继承自 {{jsxref("Error")}}.</dd>
</dl>

<h2 id="方法">方法</h2>

<p><em><code>RuntimeError</code>构造函数不包含自己的方法,但是,它确实通过原型链继承了一些方法。</em></p>

<dl>
 <dt>{{jsxref("Error.prototype.toSource", "WebAssembly.RuntimeError.prototype.toSource()")}}</dt>
 <dd>返回可能导致相同错误的代码。 继承自{{jsxref("Error")}}.</dd>
 <dt>{{jsxref("Error.prototype.toString", "WebAssembly.RuntimeError.prototype.toString()")}}</dt>
 <dd>返回表示代表指定的<code>Error</code>对象的字符串。从{{jsxref("Error")}}.</dd>
</dl>

<h2 id="样例">样例</h2>

<p>以下代码段创建了一个新的RuntimeError实例,并将其详细信息记录到控制台:</p>

<pre class="brush: js">try {
  throw new WebAssembly.RuntimeError('Hello', 'someFile', 10);
} catch (e) {
  console.log(e instanceof RuntimeError); // true
  console.log(e.message);                 // "Hello"
  console.log(e.name);                    // "RuntimeError"
  console.log(e.fileName);                // "someFile"
  console.log(e.lineNumber);              // 10
  console.log(e.columnNumber);            // 0
  console.log(e.stack);                   // 返回代码运行的位置
}</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('WebAssembly JS', '#constructor-properties-of-the-webassembly-object', 'WebAssembly constructors')}}</td>
   <td>{{Spec2('WebAssembly JS')}}</td>
   <td>Initial WebAssembly draft definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard', 'NativeError')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>Definition of standard NativeError types.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">浏览器兼容性</h2>

<div>


<p>{{Compat("javascript.builtins.WebAssembly.RuntimeError")}}</p>
</div>

<h2 id="参见">参见</h2>

<ul>
 <li><a href="/en-US/docs/WebAssembly">WebAssembly</a> overview page</li>
 <li><a href="/en-US/docs/WebAssembly/Concepts">WebAssembly concepts</a></li>
 <li><a href="/en-US/docs/WebAssembly/Using_the_JavaScript_API">Using the WebAssembly JavaScript API</a></li>
</ul>