最后执行finally

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>最后执行finally</title>
    <!-- 
        finally{a}
        解读:不论之前是否发生错误,错误是否被处理,最后都要执行代码a
     -->
</head>
<body>
    <script>
        var a=1;
        try{
            throw "我是错误提示";//自定义error massage
        }
        catch (b){
            console.log(b);//catch()捕获error name=b,b容纳了throw定义的error massage
        }
        finally{
            console.log("不管前面的对错,反正最后我都要执行");//不论前面怎样,最后都要执行的代码
        }
    </script>
</body>
</html>

posted on 2019-12-14 17:31  loongw  阅读(177)  评论(0编辑  收藏  举报

导航