美文网首页
JS如何捕获异常

JS如何捕获异常

作者: 素明诚 | 来源:发表于2020-11-23 12:29 被阅读0次

一、使用try,catch

try{
    //todo
}catch(ex){
    console.log(ex)
    //手动捕获 catch
}finally{
    //todo
}

二、使用Windows.onerror

window.onerror = function(message,source,lineNumber){
    //message,source,lineNumber等一系列的来捕获你想要的。
}

相关文章

网友评论

      本文标题:JS如何捕获异常

      本文链接:https://www.haomeiwen.com/subject/dlipiktx.html