Discuss / JavaScript / 这一节完全没有整明白

这一节完全没有整明白

Topic source

蓝色PAV

#1 Created at ... [Delete] [Delete and Lock User]

究竟怎么样才能捕捉到异步异常,其原理又是什么,完全没有概念了

繁解ffffj

#2 Created at ... [Delete] [Delete and Lock User]

把try catch作为回调函数 放到事件中去

给setTImeout加try-catch捕获的是setTimeout的错误,并不能捕获参数函数的错误。

如果要捕获printTime的错误,在printTime内try-catch,或者用函数封装

setTimeout(function(){

    try{

        printTime();

    }catch(e){

        console.log(e);

    }

}, 1000);

总之就是哪里出错哪里才能try-catch捕获。


  • 1

Reply