Complete the code to catch retrieval errors and return None.
try: result = retrieve_data(query) except [1]: result = None
Using Exception catches all errors during retrieval, allowing graceful failure.
Complete the code to retry retrieval up to 3 times on failure.
for attempt in range(3): try: data = retrieve_data(query) break except [1]: continue
Using Exception ensures all errors trigger a retry.
Fix the error in the retrieval fallback code to handle missing keys.
try: value = data['key'] except [1]: value = default_value
KeyError is raised when a dictionary key is missing, so catching it allows fallback.
Fill both blanks to log retrieval failure and return fallback data.
try: result = retrieve_data(query) except [1] as e: logger.[2](f"Retrieval failed: {e}") result = fallback_data
Catching Exception logs the error as a warning and returns fallback data.
Fill all three blanks to implement a safe retrieval with retry and fallback.
for attempt in range(3): try: data = retrieve_data(query) break except [1]: logger.[2](f"Attempt {attempt + 1} failed.") else: data = [3]
This code retries retrieval catching all exceptions, logs warnings on failure, and uses fallback data if all attempts fail.
