My R code is as follows
errors = 0
for(i in c(1:100)){
tryCatch(expr = {
API Call
}, error = {errors=errors+1}, finally = {})
further code
}
The code is meant to continue execution even if the API call fails and count the number of times error occurred. But I see that if for an iteration there is an error in API call, the code is not executed for further iterations. If I use try(), then I wont be able to count the number of errors.
The
error=argument oftryCatchshould be a function. If you pre-instantiateerrors <- 0before theforloop, there are a couple of options:My preferred is to catch and check to see if it inherits
"error":Equivalently with
try:Though the reasons I prefer that may be mostly subjective. Another way would be more internal: