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")
Run the code above in your browser using DataLab