Javascript的错误处理

<script language="javascript">
window.onerror = function(){
 alert("出错了!");
 }
</script>
</head>

<body onload="sdf()">
</body>

 

当页面中有js错误时就会触发onerror事件!

 

 

try
{
 alert("this is an example!");
 alert(sdf)
}
catch(exception)
{
 var sError = "";
 for(var i in exception)
 {
  sError += i + ":"+exception[i]+"\n";
  }
 alert(sError);
 }

</script>

 

这段代码利用try catch来处理js错误!

你可能感兴趣的:(JavaScript)