How to rethrow an error in R?

Viewed 1798

I'll catch an error using tryCatch, and attempt to handle the error. However, how can I rethrow the error if I cannot handle the error locally (i.e. delegate to error handlers of parent functions higher up in the call stack)?

I tried using signalCondition but instead of seeing the rethrown error, all I see is NULL:

> error.can.be.handled <- function(e) F
> 
> foo <- function() stop("foo stop!")
> tryCatch(foo(),
+   error = function(e) {
+       if (error.can.be.handled(e)) {
+           # handle error
+       }
+       else
+           signalCondition(e) # Rethrow error
+   }
+ )
NULL  # I expected to see 'Error in foo() : foo stop!' here

What's going wrong?

3 Answers
Related