我正在使用 R 和 rmongodb 从 MongoDB NoSQL 数据库中提取数据。我加入了try()
逻辑来捕捉不良数据引起的问题。大多数时候,try()
会捕获错误并跳过错误的数据对象。不过,偶尔,它“无法”捕捉到它,我的程序就会停止。下面是有时有效但偶尔无法进入的代码if(inherits(...))
。在调用该函数之前,我进行了检查以确保iter1
有效(据我所知) 。mongo.son.iterator.value()
事实上,我try()
在整个程序中使用了如下调用。我以前试过tryCatch
,但我认为结果是一样的。任何帮助深表感谢!
v2 <- try(mongo.bson.iterator.value(iter1))
if(inherits(v2, "try-error")) {
cat("mongo.bson.iterator.VALUE(iter1) ERROR ^^^^^^ , next!")
Sys.sleep(10)
next;
}
输出:
ItemName = VH013269
before value(iter1)
type of iter1: integer
*** caught segfault ***
address 0x7402cd5, cause 'memory not mapped'
Traceback:
1: .Call(".mongo.bson.iterator.value", iter)
2: mongo.bson.iterator.value(iter1)
3: doTryCatch(return(expr), name, parentenv, handler)
4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)
6: tryCatch(expr, error = function (e) {
call <- conditionCall(e)
if (!is.null(call)) {
if (identical(call[[1L]], quote(doTryCatch)))
call <- sys.call(-4L)
dcall <- deparse(call)[1L]
prefix <- paste("Error in", dcall, ": ")
LONG <- 75L
msg <- conditionMessage(e)
sm <- strsplit(msg, "\n")[[1L]]
w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")
if (is.na(w))
w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b")
if (w > LONG)
prefix <- paste0(prefix, "\n ")
}
else prefix <- "Error : "
msg <- paste0(prefix, conditionMessage(e), "\n")
.Internal(seterrmessage(msg[1L]))
if (!silent && identical(getOption("show.error.messages"),
TRUE)) {
cat(msg, file = stderr())
.Internal(printDeferredWarnings())
}
invisible(structure(msg, class = "try-error", condition = e))
})
7: try(mongo.bson.iterator.value(iter1))
8: eval(expr, envir, enclos)
9: eval(ei, envir)
10: withVisible(eval(ei, envir))
11: source("parcc_mci_v5.R")
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: