Dear R-devel community, There appears to be an inconsistency in R C API about the exceptions that can be raised from C code. Mapping of R C funs to corresponding R functions is as follows.
error -> stop warning -> warning REprintf -> message Rprintf -> cat Rprint/cat is of course not an exception, I listed it just for completeness. The inconsistency I would like to report is about REprintf. It cannot be caught by tryCatch(message). Warnings are errors are being caught as expected. Is there any chance to "fix"/"improve" REprintf so tryCatch(message) can catch it? So in the example below catch(Cmessage()) would behave consistently to R's catch(message("a"))? Regards, Jan Gorecki catch = function(expr) { tryCatch(expr, message=function(m) cat("caught message\n"), warning=function(w) cat("caught warning\n"), error=function(e) cat("caught error\n") ) } library(inline) Cstop = cfunction(c(), 'error("%s\\n","a"); return R_NilValue;') Cwarning = cfunction(c(), 'warning("%s\\n","a"); return R_NilValue;') Cmessage = cfunction(c(), 'REprintf("%s\\n","a"); return R_NilValue;') catch(stop("a")) #caught error catch(warning("a")) #caught warning catch(message("a")) #caught message catch(Cstop()) #caught error catch(Cwarning()) #caught warning catch(Cmessage()) #a #NULL ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel