From c40612041809fe289aba58aefa170bbe784aba1f Mon Sep 17 00:00:00 2001 From: t7yang Date: Mon, 10 Jan 2022 08:38:07 +0800 Subject: remove name attribute for zh-CN --- .../reference/global_objects/error/index.html | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/error/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/index.html b/files/zh-cn/web/javascript/reference/global_objects/error/index.html index fe9ad2deed..82acc4e18f 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/error/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/error/index.html @@ -11,11 +11,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Error

通过Error的构造器可以创建一个错误对象。当运行时错误产生时,Error的实例对象会被抛出。Error对象也可用于用户自定义的异常的基础对象。下面列出了各种内建的标准错误类型。

-

语法

+

语法

new Error([message[, fileName[,lineNumber]]])
-

参数

+

参数

message
@@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Error
可选。被创建的Error对象的lineNumber属性值。默认是调用Error构造器代码所在的文件的行号。
-

描述

+

描述

当代码运行时的发生错误,会创建新的Error 对象,并将其抛出。

@@ -47,7 +47,7 @@ const x = Error('I was created using a function call!'); ​​​​// has the same functionality as this: const y = new Error('I was constructed via the "new" keyword!'); -

Error 类型

+

Error 类型

除了通用的Error构造函数外,JavaScript还有6个其他类型的错误构造函数。更多客户端异常,详见 Exception Handling Statements

@@ -83,18 +83,18 @@ const y = new Error('I was constructed via the "new" keyword!');
创建一个error实例,表示错误的原因:给 {{jsxref("Global_Objects/encodeURI", "encodeURI()")}}或  {{jsxref("Global_Objects/decodeURI", "decodeURI()")}}传递的参数无效。
-

属性

+

属性

{{jsxref("Error.prototype")}}
允许添加属性到Error实例。
-

方法

+

方法

全局Error对象自身不包含任何方法,但从原型链中继承了一些方法.

-

Error 实例

+

Error 实例

{{page('en-US/docs/JavaScript/Reference/Global_Objects/Error/prototype', 'Description')}}

@@ -108,9 +108,9 @@ const y = new Error('I was constructed via the "new" keyword!');

{{page('en-US/docs/JavaScript/Reference/Global_Objects/Error/prototype', 'Methods')}}

-

例子

+

例子

-

抛出一个基本错误

+

抛出一个基本错误

通常你会使用{{jsxref("Statements/throw", "throw")}}关键字来抛出你创建的Error对象。可以使用 {{jsxref("Statements/try...catch", "try...catch")}} 结构来处理异常:

@@ -121,7 +121,7 @@ const y = new Error('I was constructed via the "new" keyword!'); } -

处理一个特定错误

+

处理一个特定错误

你可以通过判断异常的类型来特定处理某一类的异常,即判断 {{jsxref("Object.prototype.constructor", "constructor")}} 属性,当使用现代Javascript引擎时,可使用{{jsxref("Operators/instanceof", "instanceof")}} 关键字:

@@ -248,7 +248,7 @@ try {
{{Compat("javascript.builtins.Error")}}
-

相关链接

+

相关链接