最后执行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>

相关推荐