try{
var date=new Date();
date.test();//调用date的未定义的test方法;
document.wrire("try块执行结束<br>");
}catch(error){
with(document){
write("出现了异常<br>");
write("异常类型:"+error.name+"<br>");
write("异常消息:"+error.message);
}
}finally{
document.write("异常处理完毕!");
}

throw new Error("x must not be negative");

window.onerror = function(msg, url, line) {
if (onerror.num++ < onerror.max) {
alert("ERROR: " + msg + "\n" + url + ":" + line);
return true; //如果注释掉该语句,浏览器中还是会有错误提示,反之则没有
}
}

相关文章:

  • 2021-12-31
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-10-20
  • 2021-08-07
  • 2021-10-20
  • 2021-09-01
  • 2021-08-30
  • 2022-12-23
相关资源
相似解决方案