I'd like to catch an invalid input error within a timeout error. I wrote the script as follows. However, the timeout didn't work in this case and the program run forever. Could anyone please have a check and let me know how to fix it? Thank you.
for (lb in 1:100) {
rs <- tryCatch(
expr = {
cat("helloworld", "\n");
withTimeout({
rs_son = tryCatch(
expr = {
flag = FALSE
cat("start solnl", "\n");
ret = solnl(X, objfun = obj, confun = con, lb=lb, ub=ub);
cat("finish solnl", "\n");
},
error = function(e) {flag <- TRUE}
)
if(flag) {next}
},
timeout = 10)
},
TimeoutException = function(ex) {
cat("Timeout. Skipping.\n")
}
)
}
To be more clear, this is what I'd like to achieve. The for loop should continue no matter whether this is an invalid input error for the solnl function or timeout error.