Bird
0
0

Identify the problem in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - Error Handling
Identify the problem in this Ruby code:
begin
  puts 'Start'
  raise 'Oops'
rescue
  puts 'Rescued error'
  retry
end
ASyntax error in raise statement
BInfinite loop due to retry without condition
CMissing ensure block
DNo problem, code runs once
Step-by-Step Solution
Solution:
  1. Step 1: Understand retry behavior

    retry restarts the begin block after rescue.
  2. Step 2: Analyze code flow

    Since raise always triggers, retry causes an infinite loop.
  3. Final Answer:

    Infinite loop due to retry without condition -> Option B
  4. Quick Check:

    Retry without exit condition causes infinite loop [OK]
Quick Trick: Use retry carefully to avoid infinite loops [OK]
Common Mistakes:
  • Ignoring retry effect
  • Thinking raise syntax is wrong
  • Assuming code runs once

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes