tryCatchAll {NMdata} | R Documentation |
Catch errors, warnings, messages
Description
Catch errors, warnings, messages
Usage
tryCatchAll(expr, message = FALSE, warning = TRUE, error = TRUE)
Arguments
expr |
The expression to catch errors, warnings, messages from |
message |
Catch messages? Default is 'FALSE'. |
warning |
Catch warnings? Default is 'TRUE'. |
error |
Catch errors? Default is 'TRUE'. |
Examples
testfun <- function(x) {
message("Starting function")
if (x == 0) warning("x is zero")
if (x < 0) stop("x is negative")
message("Ending function")
x
}
## use the class of the result to test whether anything was
## caught.
res1 <- NMdata:::tryCatchAll(testfun(1))
res1
inherits(res1,"tryCatchAll")
res1b <- NMdata:::tryCatchAll(testfun(1),message=FALSE)
res1b
inherits(res1b,"tryCatchAll")
res2 <- NMdata:::tryCatchAll(testfun(0))
res2
inherits(res2,"tryCatchAll")
res3 <- NMdata:::tryCatchAll(testfun(-1))
res3
inherits(res3,"tryCatchAll")
[Package NMdata version 0.2.1 Index]