码迷,mamicode.com
首页 > 其他好文 > 详细

Error 对象

时间:2017-11-08 14:57:25      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:ret   document   err   throw   添加   isnan   对象   try   script   

<!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 处理异常。

Error 对象

标签:ret   document   err   throw   添加   isnan   对象   try   script   

原文地址:http://www.cnblogs.com/wxhhts/p/7803584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!