Bird
0
0

Identify the error in this retry logic snippet for DynamoDB in Python:

medium📝 Debug Q14 of 15
DynamoDB - with AWS SDK
Identify the error in this retry logic snippet for DynamoDB in Python:
try:
    response = client.get_item(TableName='MyTable', Key={'id': {'S': '123'}})
except ClientError as e:
    if e.response['Error']['Code'] == 'ThrottlingException':
        client.get_item(TableName='MyTable', Key={'id': {'S': '123'}})
    else:
        raise e
ANo error, code retries correctly
BShould not raise exception in else block
CError code check is incorrect
DRetry call is not inside a try-except block
Step-by-Step Solution
Solution:
  1. Step 1: Analyze retry call placement

    The retry call is made without a try-except block, so if it fails again, it will raise an unhandled exception.
  2. Step 2: Understand proper retry handling

    Retries should be wrapped in try-except to handle repeated failures gracefully.
  3. Final Answer:

    Retry call is not inside a try-except block -> Option D
  4. Quick Check:

    Retry without try-except risks unhandled errors [OK]
Quick Trick: Always wrap retries in try-except to catch repeated errors [OK]
Common Mistakes:
MISTAKES
  • Not wrapping retry calls in error handling
  • Mischecking error codes
  • Avoiding raising exceptions on unknown errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes