重新抛出异常

异常处理

method_with_error <- function() {
  tryCatch(stop("test exception"),
           error = function(e) {
             # 在此做一些局部处理,
             # 再把错误继续向外传递
             stop(e)
           })
}

msg <- tryCatch(method_with_error(),
                error = conditionMessage)
# msg = test exception

cat("msg =", msg, "\n")