# 错误
¥Error
代表运行时错误。
¥Represents a runtime error.
Error API 与 JavaScript (MDN (opens new window)) 非常相似,但有些属性尚未实现。
¥The Error API is very similar to JavaScript's (MDN (opens new window)), with some properties not being implemented yet.
# 变体
¥Variants
| 变体 | 描述 | 
|---|---|
| 错误 | 代表一般错误。 | 
| 范围误差 | 表示值不在允许值范围内的错误。 | 
| 类型错误 | 表示值不是预期类型的错误。 | 
| 语法错误 | 表示输入语法无效的错误。 | 
还可以通过转发 message 并在重载构造函数中设置 name 属性来对 Error 类进行子类化。
¥The Errorclass can also be sub-classed by forwarding message and setting the name property in the overloaded constructor.
# 构造函数
¥Constructor
- new Error(message?: string)- 构造一个新的错误对象。 - ¥Constructs a new error object. 
# 实例成员
¥Instance members
# 字段
¥Fields
- var message: string- 此错误的消息。 - ¥The message of this error. 
- var name: string- 此错误的名称。如果是 - Error,则为- "Error"。- ¥The name of this error. In case of - Error, this is- "Error".
- var stack: string- 此错误的堆栈跟踪。尚不支持,因此为空字符串。 - ¥The stack trace of this error. Not supported yet, hence an empty string. 
# 方法
¥Methods
- function toString(): string- 以 - name: message的形式返回此错误的字符串表示形式。- ¥Returns a string representation of this error in the form - name: message.