jQuery exception handling

后端 未结 3 901
感动是毒
感动是毒 2021-01-20 00:28

Is there any way I could catch any uncaught exception in javascript? I mean, all my \"dangerous\" code are in try-catch blocks. But what about exceptions that I don\'t handl

3条回答
  •  余生分开走
    2021-01-20 01:26

    How about

        function func_madness() {
            throw("This function is throwing exceptions, because \n" +
            "it can not throw polar bears and whales.\n");
        } // func_madness
    
        window.onload = function () {
            try {
                func_madness();
            } catch (err) {
                document.write("Caught it!\n
    \n" + err); } // catch } // window.onload

提交回复
热议问题