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; //如果注释掉该语句,浏览器中还是会有错误提示,反之则没有
}
}