当前位置:网站首页>try catch
try catch
2022-07-22 10:18:00 【你一定要努力,但千万别着急】
两层循环 怎么终止整个循环
let arr = [
[1, 2, 3, 4, 5],
[99, 66, 3, 1, 999]
]
try {
arr.forEach(item => {
item.forEach(itemChild => {
if (itemChild === 3) {
foreach.break = new Error // 终止整个循环
}
console.log(itemChild) // 1 2
})
})
} catch (e) {
console.log('整个循环终止')
console.log(e.message)
}
try catch
- 捕获异常 只能获取同步 无法捕获异步
- 同步 第一行没执行完 不会执行第二行
- 容许错误 并且报错 后面的代码继续执行
- throw 输出错误信息 终止程序
var arr = [1, 2, 3, 4, 5, 6]
for( var i = 0; i < arr.length; i ++ ) {
if (i === 3) {
break // 终止循环
}
console.log(i) // 0 1 2
}
边栏推荐
猜你喜欢
Spark GraphX 中的 pregel函数(转载)
AForge "failed to load the file or assembly" aforge.video.ffmpeg.dll "or one of its dependencies. The specified module cannot be found "
Reliability and repeatability of messages
How Oracle converts strings into multiple lines
Spark Jason log analysis
The luckiest geek in China: in his early twenties, he was worth more than 100 million, and retired after three startups
Creation of sparksql dataset
IDEA运行WordCount程序(详细步骤)
jvm-jmap(内存映像工具)的使用
HTB- Armageddon
随机推荐
【TA-霜狼_may-《百人计划》】图形3.3 曲面细分与几何着色器 大规模草渲染
nacos权限与数据库
栈题目:基本计算器 II
Niofiles tool class
shell script “<< EOF”我的用途和遇到的问题
ZABBIX realizes nail monitoring alarm
Foundation type
SparkSQL Dataset的创建
【校招总结】【旧文回顾】百度实习收获美团网易小米华为远景offer
文献记录(part109)--Self-Representation Based Unsupervised Exemplar Selection in a Union of Subspaces
Spark SQL built-in functions and custom functions UDF
Spark RDD算子:分区操作,mapPartitions和mapPartitionsWIthIndex
【总结思考】高可用架构设计的7大核心原则
Datablau5.0 data asset management product series heavy release
pyinstaller打包scrapy
Win10图标变白纸了,恢复方法
IO models you often encounter
Conception du modèle de données de la base de données newsql
Data model design of newsql database
Modify the contents of /etc/crontab file directly, and the scheduled task will not take effect