<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
//函数默认要求参数为数字
function sum(a,b){
a=parseInt(a);
b=parseInt(b);
//如果a或b不能转换为数字则抛出一个异常对象
if(isNaN(a) || isNaN(b)){
throw new Error("arguments are not numbers");
}
return a+b;
}
try{
//错误的调用
var s=sum("c","d");
}catch(e){
//显示异常的详细信息
alert(e.message);
}
//-->
</script>
</body>
</html>
时间: 2024-11-03 20:53:39