Skip to content
Prev 34851 / 63424 Next

error checks

On 11/13/09 8:02 AM, Tony Plate wrote:
But that's a rather heavy handed approach and could easily mask errors 
that you are not expecting.

Instead, how about using tryCatch so that you limit the errors that you 
trap and also can verify that an error was indeed trapped.  Perhaps 
something like this:


f <- function(x) if (x) stop("crash!") else NULL

res <- tryCatch(
      {
          f(TRUE)         # this will raise an error
          FALSE           # only get here if no error
      },
          error = function(e) TRUE)

## verify we saw an error
stopifnot(res)

+ seth