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

try,catch捕获错误的用法

时间:2016-03-23 19:53:53      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <script>
        var txt="";
        function message(aa)
        {
            try
            {
                txt = JSON.parse(aa)
            }
            catch(err)
            {
                txt="本页有一个错误。\n\n";
                txt+="错误描述:" + err.message + "\n\n";
                txt+="点击确定继续。\n\n";
                alert(txt);
            }
            return txt;
        }
    </script>
</head>

<body>
<input type="button" value="查看消息" onclick="message()" />
</body>

</html>

 

try,catch捕获错误的用法

标签:

原文地址:http://www.cnblogs.com/suoking/p/5312294.html

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