try_catch_warnings: Try Catch with Warning Handling

View source: R/adls_try_catch_warnings.R

try_catch_warningsR Documentation

Try Catch with Warning Handling

Description

Try Catch with Warning Handling

Usage

try_catch_warnings(expr, character = FALSE)

Arguments

expr

An expression to be evaluated.

character

A logical indicating if the returned error and warning should be characters (character = TRUE) or language (character = FALSE).

Value

The try_catch_warnings() funciton returns a list with three elements

  • values is the evaluated expr or NULL if the evaluations throws an error.

  • warning is any warning given while evaluating expr. When character = FALSE, the default, warning is a simpleWarning, otherwise it is a character.

  • error is any error given while trying to evaluate expr. When character = FALSE, the default, error is a simpleError, otherwise it is a character.

Examples

# No errors or warnings
try_catch_warnings(log(2))

# Warnings
try_catch_warnings(log(-1))

# Errors
try_catch_warnings(stop("Error Message"))
try_catch_warnings(stop("Error Message"), character = TRUE)


EpiForsk documentation built on Aug. 21, 2025, 5:31 p.m.