<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script type="text/javascript">
function test(a,b){
document.write(a+"除以"+b+"的计算结果是:");
a=Number(a);
b=Number(b);//转换成数字
try{
if(isNaN(a)||isNaN(b)){
throw'运算数是非数字';//异常信息传入ex变量
}
if(b==0){
throw'除数是0';//异常信息传入ex变量
}
document.write(a/b);
}catch(ex){
document.write("异常信息"+ex);
}
finally{
document.write("   (异常处理结束)<br />");
}
}
(function(){
test('x',5);
test(100,2);
test(100,0);
test(50,'20');//其中调用Number方法转成数字
})();
</script>
<body>
</body>
</html>