首页 > 学院 > 开发设计 > 正文

throw 语句

2019-11-18 11:08:27
字体:
来源:转载
供稿:网友

 

产生一个能被 try...catch...finally 语句处理的错误情形。

throw exception

必选的 exception 参数可以是任何表达式

说明

下面的例子根据传递进来的值扔出一个错误,然后举例说明那个错误是如何在 try...catch...finally语句的层次中被处理的:

function TryCatchDemo(x){   try {      try {      if (x == 0)   // 估参数的值。         throw "x equals zero";   // 扔出一个错误。      else         throw "x does not equal zero";   // 扔出一个不同的错误。      }      catch(e) {   // 在这儿处理 "x = 0" 的错误。         if (e == "x equals zero")   // 检查错误能否在这儿被处理。            return(e + " handled locally.");   // 返回对象错误消息。         else   // 不能在这儿处理这个错误。            throw e;   // 重新扔出该错误给下一个      }   // 错误处理程序。   }   catch(e) {   // 在此处理其他错误。      return(e + " handled higher up.");   // 返回错误消息。   }}document.write(TryCatchDemo(0));document.write(TryCatchDemo(1));

要求

版本 5

请参阅

try...catch 语句



上一篇:this 语句

下一篇:return 语句

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表