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

View in English Always switch to English

WebAssembly.RuntimeError

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2017年10月以降、すべてのブラウザーで利用可能です。

WebAssembly.RuntimeError オブジェクトは、 WebAssembly がトラップを指定するたびに例外として発生するエラー型です。

コンストラクター

WebAssembly.RuntimeError()

新しい WebAssembly.RuntimeError オブジェクトを生成します。

インスタンスプロパティ

WebAssembly.RuntimeError.prototype.message

エラーメッセージ。 Error から継承しています。

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 から継承しています。

インスタンスメソッド

WebAssembly.RuntimeError.prototype.toSource()

同じエラーを評価できるコードを返します。 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); // コードが実行されていた位置を返す
}

仕様書

仕様書
WebAssembly JavaScript Interface
# exceptiondef-runtimeerror
ECMAScript® 2027 Language Specification
# sec-native-error-types-used-in-this-standard

ブラウザーの互換性

関連情報