Possible Duplicate:
Exception handling in R
Does anyone have idea on how to catch an error or an exception in R?
Possible Duplicate:
Exception handling in R
Does anyone have idea on how to catch an error or an exception in R?
Like Joshua said: use tryCatch.  Include an error argument, which should be a function accepting one parameter (the error, typically called e).
tryCatch(
  stop("you threw an error"), 
  error = function(e) 
  {
    print(e$message) # or whatever error handling code you want
  }
)
 
    
    It really depends on what you mean by "catch".  Look at tryCatch and withCallingHandlers.
 
    
    Have you looked into stop?
This will allow you to catch exceptions that you define.
