WebAssembly.CompileError
WebAssembly.CompileError
对象表示 WebAssembly 解码或验证期间发生的错误。
构造函数
WebAssembly.CompileError()
-
创建一个新的
WebAssembly.CompileError
对象。
实例属性
WebAssembly.CompileError.prototype.message
-
错误消息。从
Error
继承。 WebAssembly.CompileError.prototype.name
-
错误名称。从
Error
继承。 WebAssembly.CompileError.prototype.cause
-
错误原因。从
Error
继承。 WebAssembly.CompileError.prototype.fileName
非标准-
引发此错误的文件的路径。从
Error
继承。 WebAssembly.CompileError.prototype.lineNumber
非标准-
引发此错误的行号。从
Error
继承。 WebAssembly.CompileError.prototype.columnNumber
非标准-
引发此错误的行中的列号。从
Error
继承。 WebAssembly.CompileError.prototype.stack
非标准-
堆栈跟踪。从
Error
继承。
实例方法
WebAssembly.CompileError.prototype.toString()
-
返回表示指定
Error
对象的字符串。从Error
继承。
示例
创建新的 CompileError 实例
以下代码片段创建了一个新的 CompileError
实例,并将其详细信息记录到控制台。
js
try {
throw new WebAssembly.CompileError("Hello", "someFile", 10);
} catch (e) {
console.log(e instanceof CompileError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "CompileError"
console.log(e.fileName); // "someFile"
console.log(e.lineNumber); // 10
console.log(e.columnNumber); // 0
console.log(e.stack); // returns the location where the code was run
}
规范
规范 |
---|
WebAssembly JavaScript 接口 # exceptiondef-compileerror |
ECMAScript® 2026 语言规范 # sec-native-error-types-used-in-this-standard |
浏览器兼容性
加载中…