These functions provide a mechanism for handling unusual conditions, including errors and warnings.
tryCatch(expr, …, finally)
withCallingHandlers(expr, …)<p></p><p>signalCondition(cond)</p><p>simpleCondition(message, call = NULL)
simpleError (message, call = NULL)
simpleWarning (message, call = NULL)
simpleMessage (message, call = NULL)</p><p>errorCondition(message, ..., class = NULL, call = NULL)
warningCondition(message, ..., class = NULL, call = NULL)</p><p># S3 method for condition
as.character(x, …)
# S3 method for error
as.character(x, …)
# S3 method for condition
print(x, …)
# S3 method for restart
print(x, …)</p><p>conditionCall(c)
# S3 method for condition
conditionCall(c)
conditionMessage(c)
# S3 method for condition
conditionMessage(c)</p><p>withRestarts(expr, …)</p><p>computeRestarts(cond = NULL)
findRestart(name, cond = NULL)
invokeRestart(r, …)
invokeRestartInteractively(r)</p><p>isRestart(x)
restartDescription(r)
restartFormals(r)</p><p>suspendInterrupts(expr)
allowInterrupts(expr)</p><p>.signalSimpleWarning(msg, call)
.handleSimpleError(h, msg, call)
.tryResumeInterrupt()</p>
| Parameter | Description |
|---|---|
c |
a condition object. |
call |
call expression. |
cond |
a condition object. |
expr |
expression to be evaluated. |
finally |
expression to be evaluated before returning or exiting. |
h |
function. |
message |
character string. |
msg |
character string. |
name |
character string naming a restart. |
r |
restart object. |
x |
object. |
class |
character string naming a condition class. |
… |
additional arguments; see details below. |
# NOT RUN {
tryCatch(1, finally = print("Hello"))
e <- simpleError("test error")
# }
# NOT RUN {
stop(e)
tryCatch(stop(e), finally = print("Hello"))
tryCatch(stop("fred"), finally = print("Hello"))
# }
# NOT RUN {
tryCatch(stop(e), error = function(e) e, finally = print("Hello"))
tryCatch(stop("fred"), error = function(e) e, finally = print("Hello"))
withCallingHandlers({ warning("A"); 1+2 }, warning = function(w) {})
# }
# NOT RUN {
{ withRestarts(stop("A"), abort = function() {}); 1 }
# }
# NOT RUN {
withRestarts(invokeRestart("foo", 1, 2), foo = function(x, y) {x + y})
##--> More examples are part of
##--> demo(error.catching)
# }