Junior — Senior
Decorator that automatically re-invokes a function after an exception
livecode
Task condition
Create a decorator that will infinitely repeat the function call if an exception occurs during its execution. The decorator should catch any exceptions, print them (if desired), and call the original function again until it completes without errors.
@repeat_on_error
def my_func():
# function body that may throw exceptions
...
Requirements:
- The decorator does not accept additional parameters.
- The function should be restarted each time an exception occurs.
- The retry loop continues infinitely until the function executes successfully.
- Logging the error before retrying can be added if necessary.