We know that calling Rf_error()
should be avoided in Rcpp as it involves a longjmp over C++ destructors on the stack. This is why we rather throw C++ exceptions in
One of the solutions I came up with involves calling the R's warning
function from Rcpp:
// [[Rcpp::export]]
void test() {
Test t;
Function warning("warning");
warning("test"); // here R errors are caught and transformed to C++ exceptions
}
which gives the correct behavior if warn>2
:
start
end
Error in eval(expr, envir, enclos) : (converted from warning) test
I wonder if anybody has a better idea for that.