trycatch抛出错误

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>

    <body>
        <input name="bn" type="button" οnclick="myMethod();" value="捕获异常">
    </body>
    <script type="text/javascript">
        function myMethod() {
            var array = null;
            try {
                document.write(array[0]);
            } catch(err) {
                document.writeln("Error name: " + err.name + "");
                document.write("<br>")
                document.writeln("Error message: " + err.message);
            }
        }
    </script>

</html>

猜你喜欢

转载自blog.csdn.net/qq_36521848/article/details/84331026