Error 对象

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script type="text/javascript">
function half(n){
if(isNaN(n)){
var e1=new Error();
e1.message="half()的参数不是数字";
throw e1;
return;
}
return n/3;
}
(function(){
try{
half("haha");
}catch(e){
document.write("错误信息:"+e.message);
}
})();
</script>
<body>
</body>
</html>

................................................

创建了e1 这个error 对象,为e1的message添加描述异常信息,并抛出e1 这个异常。后面使用try catch 处理异常。

posted @ 2017-11-08 13:24  我喜欢喝糖水  阅读(129)  评论(0编辑  收藏  举报
我喜欢喝糖水的博客友链:股票指标编程学习