js中的try/catch

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>robot</title>
    <script>
        window.onload = function(){
            try{
                var message = document.getElementById("message");
            } catch (error){
                console.log("Error:" + error.message);
            }
        }

    </script>
</head>
<body>

</body>
</html>

 

posted @ 2018-07-25 15:03  道高一尺  阅读(1396)  评论(0编辑  收藏  举报