? Thu, 21 Sep 2023 15:10:56 +0200 Jan Gorecki <j.gorecki at wit.edu.pl> ?????:
Do you by any chance know any examples of using R_withCallingErrorHandler? Or could you modify your example to use this instead?
Calling handlers are different from exiting handlers established by
tryCatch. Instead of replacing the value of an expression that raised a
condition with the return value of the exiting handler, calling
handlers get an opportunity to clean up or invoke a so-called restart,
but when they return, the execution continues:
withCallingHandlers(stop("fatal"), error = function(cond) {
writeLines("I'm a calling handler, this is my argument:")
str(cond)
})
# I'm a calling handler, this is my argument:
# List of 2
# $ message: chr "fatal"
# $ call : language withCallingHandlers(stop("fatal"), ...
# - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
# Error in withCallingHandlers(stop("fatal"), error = function(cond) { :
# fatal
Since setting up restarts will involve calling into R, a complete
solution will involve much more code than R_tryCatchError.
Best regards, Ivan