18
These days people will advise you to use ScheduledExecutorService to implement this kind of try-catch-retry functionality, as Thread.sleep() is considered outdated and potentially bad for performance. I was going to point you to a good answer on this by cletus, but can't for the life of me find it. I'll update my answer if I can dig it up.
EDIT: found it: How to retry function request after a certain time Hopefully this is of some help to you.
I can suggest to emulate kinda the same (I'm not sure about semantics of retry):
def retry(handler, c) {
try {
c()
} catch(e) {
handler(e)
retry(handler, c) // restart from beginning
}
}
def handler = {e ->
// handles error
}
retry(handler) {
do_something // exception raised
}