Catching exceptions and returning them as errors for R