try_catch: Try to evaluate an expressions and capture any messages,...

Description Usage Arguments Value Examples

View source: R/try-catch.R

Description

This function is similar to tryCatch(), except that, by default, errors are captured and presented using error(). Messages and warnings are not captured by this function. In addition, a "finally" expression can be specified which is evaluated at the end of the call no matter the result.

Usage

1
try_catch(expr, on_error, finally)

Arguments

expr

(expression) The expression to evaluate

on_error

(function, optional) A function describing what to do in the event of a error in the above expression. The function must take a single argument, which is the simpleError(). If missing or NULL, errors are not caught. Default: error() called with the error's message prefixed by the calling function name.

finally

(expression, optional) An expression to evaluate at the end of the call. If missing or NULL, nothing is actioned.

Value

The result of the evaluated expression

Examples

1
2
3
4
5
## Not run: 
  try_catch(x <- "foo")
  try_catch(stop("This is an error"))

## End(Not run)

msgr documentation built on Dec. 16, 2019, 5:41 p.m.