Learn R Programming

simsalapar (version 1.0-2)

tryCatch.W.E: Catching and Storing Warnings and Errors Simultaneously

Description

Catches and saves both warnings (warning) and errors (stop) and in the case of a warning, also the computed result.

Usage

tryCatch.W.E(expr)

Arguments

expr
expression to be evaluated, typically a function call.

Value

Details

This function is particularly useful in large(r) simulation studies to check all computations and guarantee their correctness.

References

see simsalapar-package.

See Also

the base function tryCatch() and demo(error.catching). Also, doCallWE(), of which tryCatch.W.E() is the workhorse.

Examples

Run this code
## Adapted from demo(error.catching) :
str(r1 <- tryCatch.W.E( log( 2 ) ) )
str(r2 <- tryCatch.W.E( log(-1 ) ) )
str(r3 <- tryCatch.W.E( log("a") ) )
stopifnot(is.null(r1$warning),
          is.na  (r2$value),   inherits(r2$warning, "warning"),
          is.null(r3$warning), inherits(r3$value, "error"))

Run the code above in your browser using DataLab