R provides some method of adding handlers for errors and warnings. You can use something like
.Internal(.addCondHands("error", list(error = function(e) {print("ok")}), .GlobalEnv, NULL, TRUE))
add callback function for error. I did not find much documentation for this, but you can see the source for withCallingHandlers and tryCatch to find out how to use it.
Edit:
And also I found that one method has a callback after an error, but not in a pure R-way. It relies on the Rstudio error callback mechanism:
If you use Rstudio, you will find the global "error" option that Rstudio uses as an error callback function. You can see this: getOption("error") and change it as follows:
f <- function(){ print("ok") } options(error = f)
And if you want to collect the last error message, you can use geterrmessage() , which is built into R.
Consistency
source share