The throw statement allows you to create an exception.
throw声明可以让你建立例外(情况)
Examples
实例
The throw statement [throw语句]]
How to use the throw statement.
怎样使用throw声明
The Throw Statement
The throw statement allows you to create an exception. If you use this statement together with the try...catch statement, you can control program flow and generate accurate error messages.
如果你把throw声明和try...catch声明组合起来使用,你可以控制程序流程并引出精确的错误信息
Syntax语法
throw(exception) |
The exception can be a string, integer, Boolean or an object.
例外可以是串,整数,布尔或是对象。
Note that throw is written in lowercase letters. Using uppercase letters will generate a JavaScript error!
注意throw是要小写的,不然会出错
Example 1
例子1
The example below determines the value of a variable called x. If the value of x is higher than 10 or lower than 0 we are going to throw an error. The error is then caught by the catch argument and the proper error message is displayed:
下面的例子(结果)决定于变量x的值。如果x的值大于10或是小于0就出现不同的错误提示
<html> |
本文介绍了如何使用throw声明来创建异常,并通过与try...catch语句的结合使用来控制程序流程及生成准确的错误信息。文章还提供了一个具体的示例,展示了如何根据不同条件抛出不同类型的异常,并捕获这些异常来显示相应的错误消息。
2610

被折叠的 条评论
为什么被折叠?



