How to catch error / exception in R?

Possible duplicate:
Exception handling in R

Does anyone have an idea on how to catch an error or exception in R?

+5
source share
3 answers

As Joshua said: use tryCatch. Include an argument error, which should be a function that takes one parameter (an error, commonly called e).

tryCatch(
  stop("you threw an error"), 
  error = function(e) 
  {
    print(e$message) # or whatever error handling code you want
  }
)
+4
source

It really depends on what you mean by "trick". Take a look tryCatchand withCallingHandlers.

+2
source

stop? , .

+1

All Articles