JS如何捕获异常

一、使用try,catch

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

二、使用Windows.onerror

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

你可能感兴趣的:(JS如何捕获异常)