try {
var arr = ["第一名","第二名","第三名","第四名"];
// 执行到第3次,结束循环
arr.forEach(function(item,index){
if (item == "第三名") {
throw new Error("第三名");
}
console.log(item);// 第一 第二
});
} catch(e) {
if(e.message!="第三名") throw e;
};
// 下面的代码不影响继续执行
console.log("以下方代码");//下方代码
try中还是catch中的throw的作用都是是中断后面所有语句的执行,并且抛出错误源(throw 后面的内容)