JS 的try catch运用记录
try 测试代码块中的错误。
catch 处理错误。
throw 创建自定义错误。
finally 在 try 和 catch 之后,无论结果如何,始终执行
在回答csdn问题是,用到forEach循环,需要在满足条件是结束循环。当时不想换写法了,就去找了一下,果真有嘻嘻嘻嘻
try catch 抛出异常throw 打断forEach
let arr = [1,2,3,4,5,6]
arr.forEach(item=>{
try{
console.log(item)
if(item>3){
console.log(item)
throw '错'
}
}catch(e){
console.log(e)
}
})
遇到再记录············