WebAssembly.RuntimeError

WebAssembly.RuntimeError 物件是每當 WebAssembly 指定 陷阱 時丟擲的錯誤型別。

建構函式

WebAssembly.RuntimeError()

建立一個新的 WebAssembly.RuntimeError 物件。

例項屬性

WebAssembly.RuntimeError.prototype.message

錯誤訊息。繼承自 Error

WebAssembly.RuntimeError.prototype.name

錯誤名稱。繼承自 Error

WebAssembly.RuntimeError.prototype.cause

錯誤原因。繼承自 Error

WebAssembly.RuntimeError.prototype.fileName 非標準

引發此錯誤的檔案路徑。繼承自 Error

WebAssembly.RuntimeError.prototype.lineNumber 非標準

引發此錯誤的檔案中的行號。繼承自 Error

WebAssembly.RuntimeError.prototype.columnNumber 非標準

引發此錯誤的行中的列號。繼承自 Error

WebAssembly.RuntimeError.prototype.stack 非標準

堆疊跟蹤。繼承自 Error

例項方法

WebAssembly.RuntimeError.prototype.toString()

返回表示指定的 Error 物件的字串。繼承自 Error

示例

建立新的 RuntimeError 例項

以下程式碼段建立了一個新的 RuntimeError 例項,並將它的詳細資訊記錄到控制檯

js
try {
  throw new WebAssembly.RuntimeError("Hello", "someFile", 10);
} catch (e) {
  console.log(e instanceof WebAssembly.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); // returns the location where the code was run
}

規範

規範
WebAssembly JavaScript 介面
# exceptiondef-runtimeerror
ECMAScript 語言規範
# sec-native-error-types-used-in-this-standard

瀏覽器相容性

BCD 表格僅在啟用 JavaScript 的瀏覽器中載入。

另請參閱