Error.prototype.message

Baseline Widely available

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

message プロパティは、人間が読めるエラーの説明です。

解説

このプロパティは、利用可能または設定されている場合、エラーの簡潔な説明を含みます。SpiderMonkey は、例外の message プロパティを広範囲に渡って使用します。name プロパティは message プロパティとの組み合わせで、Error の文字列表現を生成するために Error.prototype.toString() メソッドにより使用されます。

既定で message プロパティは空文字列ですが、この振る舞いは、 Error コンストラクターの第一引数としてメッセージを指定することにより、インスタンスを上書きできます。

独自のエラーを発生させる

js
var e = new Error("Could not parse input");
// e.message は 'Could not parse input'
throw e;

仕様書

Specification
ECMAScript® 2025 Language Specification
# sec-error.prototype.message

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
message

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報