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. |
浏览器兼容性
BCD tables only load in the browser