try{
  //代码段
  if(x>10)  throw "Err1"    //throw : 抛出错误,可以在catch中接到错误信息 else if(x<0) throw "Err2"
}
catch(er) {
  //错误处理代码
  if(er=="Err1")  alert("Error! The value is too high") if(er == "Err2")  alert("Error! The value is too low")  
}

//示例:

<script type="text/javascript">
onerror=handleErr
var txt=""

function handleErr(msg,url,l)
{
txt="There was an error on this page.\n\n"
txt+="Error: " + msg + "\n"
txt+="URL: " + url + "\n"
txt+="Line: " + l + "\n\n"
txt+="Click OK to continue.\n\n"
alert(txt)
return true
}

function message()
{
adddlert("Welcome guest!")
}
</script>


相关文章:

  • 2021-07-31
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案