Hey everybody I\'m working on a data scraping project and I\'m looking for a clean way to repeat a function call if an exception is raised.
Pseudo-code:
I like to do these problems with recursion:
def tryfor(times, on_failure, excepts, func, *args, **kwargs):
if times < 1:
raise on_failure()
try:
return func(*args, **kwargs)
except excepts:
return tryfor(times-1, on_failure, excepts, func, *args, **kwargs)
tryfor(3, PermanentException, (SomeError,), dostuff,1,2)