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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
message |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.