📜  如果出错,则循环中的下一个元素 - R 编程语言代码示例

📅  最后修改于: 2022-03-11 14:51:58.793000             🧑  作者: Mango

代码示例1
# This solution still prints the error but doesn't stop the loop
for (i in 1:10) {
  tryCatch({
    print(i)
    if (i==7) stop("Urgh, the iphone is in the blender !")
  }, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}

[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
ERROR : Urgh, the iphone is in the blender ! 
[1] 8
[1] 9
[1] 10