aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/error/message/index.html
blob: 7979ed0998360dfa5615ee11e2900685870b3d6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
---
title: Error.prototype.message
slug: Web/JavaScript/Reference/Global_Objects/Error/message
translation_of: Web/JavaScript/Reference/Global_Objects/Error/message
---
<div>{{JSRef("Global_Objects", "Error", "EvalError,InternalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError")}}</div>

<h2 id="Summary">概述</h2>

<p><code><strong>message</strong></code> 属性是有关错误信息,人类易读的(human-readable)描述。</p>

<h2 id="Description">描述</h2>

<p>如果该属性已经被设置,则该属性包含了错误的一个简短描述。<a href="/en-US/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a> 大量应用 <code>message</code> 属性在异常方面。 <code>message</code> 属性结合 {{jsxref("Error.prototype.name", "name")}} 属性一起被  {{jsxref("Error.prototype.toString()")}} 方法用来创建错误的字符串形式。</p>

<p>默认情况下,<code>message</code> 属性是一个空字符串,但是可以通过指定一段信息作为 {{jsxref("Error", "Error constructor")}} 的第一个参数创建一个实例来改变该属性值。</p>

<h2 id="Examples">示例</h2>

<h3 id="Example:_Throwing_a_custom_error">例子:抛出一个自定义错误</h3>

<pre class="brush: js">var e = new Error("Could not parse input"); // e.message is "Could not parse input"
throw e;
</pre>

<h2 id="规范">规范</h2>

{{Specifications}}

<h2 id="浏览器兼容性">浏览器兼容性</h2>

{{Compat}}

<h2 id="See_also">相关链接</h2>

<ul>
 <li>{{jsxref("Error.prototype.name")}}</li>
 <li>{{jsxref("Error.prototype.toString()")}}</li>
</ul>