//异常处理 try,throw,catch的使用
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function myfunction(){
try{
var node=document.getElementById('inputid').value;
if(node=="") throw ("cant't be empty");
if(isNaN(node)) throw("cant't be NaN");
}
catch(err){
var msg=document.getElementById("hid");
msg.innerHTML="ERROR MESSAGE IS:"+err+".";
}
}
</script>
input a number between 1-10:<br/>
<input type="text" id="inputid">
<button onclick="myfunction()">check</button>
<h1 id="hid"></h1>
</body>
</html>