Bird
0
0

What is wrong with this retry decorator that causes it to retry only once?

medium📝 Debug Q7 of 15
Selenium Python - Advanced Patterns
What is wrong with this retry decorator that causes it to retry only once?
def retry(func):
    def wrapper():
        try:
            return func()
        except Exception:
            return func()
    return wrapper
AIt retries infinitely causing a crash
BIt retries only once because there is no loop for multiple attempts
CIt does not catch exceptions properly
DIt returns None instead of function result
Step-by-Step Solution
Solution:
  1. Step 1: Analyze retry attempts

    Decorator tries func once, if exception occurs, tries func once more.
  2. Step 2: Identify missing loop

    No loop means only 2 total attempts, not multiple retries.
  3. Final Answer:

    It retries only once because there is no loop for multiple attempts -> Option B
  4. Quick Check:

    Retry needs loop for multiple attempts [OK]
Quick Trick: Use loop to retry multiple times, not just once [OK]
Common Mistakes:
  • Assuming except block retries infinitely
  • Missing loop for retries
  • Confusing exception handling with retry count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes