【发布时间】:2011-12-26 23:49:29
【问题描述】:
我已经阅读了一些关于 tryCatch 和 cuzzins 的其他 SO 问题,以及文档:
- Exception handling in R
- catching an error and then branching logic
- How can I check whether a function call results in a warning?
- Problems with Plots in Loop
但我还是不明白。
我正在运行一个循环,如果出现以下几种错误中的任何一种,我想跳到next:
for (i in 1:39487) {
# EXCEPTION HANDLING
this.could.go.wrong <- tryCatch(
attemptsomething(),
error=function(e) next
)
so.could.this <- tryCatch(
doesthisfail(),
error=function(e) next
)
catch.all.errors <- function() { this.could.go.wrong; so.could.this; }
catch.all.errors;
#REAL WORK
useful(i); fun(i); good(i);
} #end for
(顺便说一句,我找不到next 的文档)
当我运行它时,R 按喇叭:
Error in value[[3L]](cond) : no loop for break/next, jumping to top level
我在这里缺少什么基本点? tryCatch 显然在 for 循环内,那么为什么 R 不知道呢?
【问题讨论】:
标签: r error-handling exception-handling try-catch