Bird
0
0

This code snippet tries to implement a fallback but has a bug:

medium📝 Analysis Q14 of 15
Microservices - Resilience Patterns
This code snippet tries to implement a fallback but has a bug:
def get_data():
    try:
        return call_service()
    except:
        call_fallback()
What is the bug here?
AThe code does not catch exceptions
BThe try block does not call the service
CThe except block should raise an error
DThe fallback function is not returned
Step-by-Step Solution
Solution:
  1. Step 1: Check try-except behavior

    The try block returns the service call result, but except calls fallback without returning it.
  2. Step 2: Identify missing return

    Without returning fallback's result, the function returns None on failure instead of fallback data.
  3. Final Answer:

    The fallback function is not returned -> Option D
  4. Quick Check:

    Missing return in except causes None [OK]
Quick Trick: Always return fallback result in except block [OK]
Common Mistakes:
MISTAKES
  • Forgetting to return fallback data
  • Misunderstanding try-except flow
  • Assuming fallback raises error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes