InterceptExceptions: InterceptExceptions

View source: R/warnings.R

InterceptExceptionsR Documentation

InterceptExceptions

Description

This function intercepts warning and error messages produced from running expr and passes them to warning.handler and error.handler. Note that execution of expr is stopped after the first error.

Usage

InterceptExceptions(expr, warning.handler = NULL, error.handler = NULL)

Arguments

expr

The expression whose warnings are to be intercepted.

warning.handler

The function that handles intercepted warnings.

error.handler

The function that handles intercepted errors.

Value

The value from evaluating expr.

Examples

addExclamationMark <- function(warn)
{
    warning(warn$message, "!")
}
## Intercepts a warning and rethrows it with an
## exclamation mark.
InterceptExceptions(warning("This is a warning"),
                    warning.handler = addExclamationMark)

addQuestionMark <- function(error)
{
    warning(error$message, "?")
}
## Intercepts the error from throwsAWarning and rethrows it with an
## exclamation mark.
InterceptExceptions(stop("Stop"), error.handler = addQuestionMark)

Displayr/flipU documentation built on March 2, 2024, 4:35 a.m.