このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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 ⁨2017年10月⁩.

WebAssembly.CompileError() コンストラクターは、新しい WebAssembly の CompileError オブジェクトを生成します。これは WebAssembly のデコードまたは検証中のエラーを示します。

構文

js
new WebAssembly.CompileError();
new WebAssembly.CompileError(message);
new WebAssembly.CompileError(message, fileName);
new WebAssembly.CompileError(message, fileName, lineNumber);

引数

message 省略可

このエラーの人間が読める説明です。

fileName 省略可

例外が発生したコードを含むファイル名です。

lineNumber 省略可

例外が発生したコードの行番号です。

新しい 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); // コードの実行されていた位置を返す
}

仕様書

Specification
WebAssembly JavaScript Interface
# exceptiondef-compileerror
ECMAScript® 2026 Language Specification
# sec-nativeerror-constructors

ブラウザーの互換性

関連情報