--- title: WebAssembly.RuntimeError() slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError ---
WebAssembly.RuntimeError()构造函数创建一个新的WebAssembly RuntimeError对象---一个每当WebAssembly陷入指定陷阱时将抛出的类型。
new WebAssembly.RuntimeError(message, fileName, lineNumber)
message {{optional_inline}}fileName {{optional_inline}}{{non-standard_inline}}lineNumber {{optional_inline}}{{non-standard_inline}}RuntimeError构造函数不包含其自身特有的属性,但是,它确实通过原型链继承了某些属性。
WebAssembly.RuntimeError.prototype.constructormessage属性,但在SpiderMonkey中,它继承了{{jsxref("Error.prototype.message")}}。RuntimeError构造函数不包含自己的方法,但是,它确实通过原型链继承了一些方法。
Error对象的字符串。从{{jsxref("Error")}}.以下代码段创建了一个新的RuntimeError实例,并将其详细信息记录到控制台:
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); // 返回代码运行的位置
}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('WebAssembly JS', '#constructor-properties-of-the-webassembly-object', 'WebAssembly constructors')}} | {{Spec2('WebAssembly JS')}} | Initial WebAssembly draft definition. |
| {{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard', 'NativeError')}} | {{Spec2('ESDraft')}} | Definition of standard NativeError types. |
{{Compat("javascript.builtins.WebAssembly.RuntimeError")}}