一、使用try,catch
try{
//todo
}catch(ex){
console.log(ex)
//手动捕获 catch
}finally{
//todo
}
二、使用Windows.onerror
window.onerror = function(message,source,lineNumber){
//message,source,lineNumber等一系列的来捕获你想要的。
}
try{
//todo
}catch(ex){
console.log(ex)
//手动捕获 catch
}finally{
//todo
}
window.onerror = function(message,source,lineNumber){
//message,source,lineNumber等一系列的来捕获你想要的。
}
本文标题:JS如何捕获异常
本文链接:https://www.haomeiwen.com/subject/dlipiktx.html
网友评论