WebAssembly.RuntimeError()

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

语法

new WebAssembly.RuntimeError(message, fileName, lineNumber)

参数

message 可选
有可读性的错误信息。
fileName 可选
包含导致异常的代码的文件名。
lineNumber 可选
导致异常的代码的行号。

属性

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

WebAssembly.RuntimeError.prototype.constructor
创建示例原型的特定函数。
WebAssembly.RuntimeError.prototype.message
错误信息。 尽管ECMA-262指定URIError应提供自己的message属性,但在SpiderMonkey中,它继承了Error.prototype.message
WebAssembly.RuntimeError.prototype.name
错误名称。继承自 Error.
WebAssembly.RuntimeError.prototype.fileName
报出错误的文件路径。继承自 Error.
WebAssembly.RuntimeError.prototype.lineNumber
报出错误的代码所在文件中的行数。继承自Error.
WebAssembly.RuntimeError.prototype.columnNumber
报出错误的代码所在文件中的列数。继承自 Error.
WebAssembly.RuntimeError.prototype.stack
堆栈跟踪。 继承自 Error.

方法

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

WebAssembly.RuntimeError.prototype.toSource()
返回可能导致相同错误的代码。 继承自Error.
WebAssembly.RuntimeError.prototype.toString()
返回表示代表指定的Error对象的字符串。从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
WebAssembly JavaScript Interface
WebAssembly constructors
Working Draft Initial WebAssembly draft definition.
ECMAScript (ECMA-262)
NativeError
Living Standard Definition of standard NativeError types.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
RuntimeErrorChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
RuntimeError() constructorChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

参见