有TRY...CATCH...,语法如下:
try
  tryStatement
catch(exception)
  catchStatement
举例如下:
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));