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