Aliases: conditions condition computeRestarts conditionCall conditionMessage findRestart invokeRestart tryInvokeRestart invokeRestartInteractively isRestart restartDescription restartFormals signalCondition simpleCondition simpleError simpleWarning simpleMessage errorCondition warningCondition tryCatch withCallingHandlers withRestarts suspendInterrupts allowInterrupts globalCallingHandlers .signalSimpleWarning .handleSimpleError .tryResumeInterrupt as.character.condition as.character.error conditionCall.condition conditionMessage.condition print.condition print.restart
Keywords: programming error
### ** Examples tryCatch(1, finally = print("Hello"))
[1] "Hello"
[1] 1
e <- simpleError("test error") ## Not run: ##D stop(e) ##D tryCatch(stop(e), finally = print("Hello")) ##D tryCatch(stop("fred"), finally = print("Hello")) ## End(Not run) tryCatch(stop(e), error = function(e) e, finally = print("Hello"))
[1] "Hello"
<simpleError: test error>
tryCatch(stop("fred"), error = function(e) e, finally = print("Hello"))
[1] "Hello"
<simpleError in doTryCatch(return(expr), name, parentenv, handler): fred>
withCallingHandlers({ warning("A"); 1+2 }, warning = function(w) {})
Warning in withCallingHandlers({: A
[1] 3
## Not run: ##D { withRestarts(stop("A"), abort = function() {}); 1 } ## End(Not run) withRestarts(invokeRestart("foo", 1, 2), foo = function(x, y) {x + y})
[1] 3
##--> More examples are part of ##--> demo(error.catching)