WebAssembly.CompileError

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2017.

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("你好", "某个文件", 10);
} catch (e) {
  console.log(e instanceof CompileError); // true
  console.log(e.message); // "你好"
  console.log(e.name); // "CompileError"
  console.log(e.fileName); // "某个文件"
  console.log(e.lineNumber); // 10
  console.log(e.columnNumber); // 0
  console.log(e.stack); // 返回运行代码的位置
}

规范

Specification
WebAssembly JavaScript Interface
# exceptiondef-compileerror
ECMAScript® 2026 Language Specification
# sec-native-error-types-used-in-this-standard

浏览器兼容性

参见