Bird
0
0

Find the problem in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Error Handling
Find the problem in this Ruby code snippet:
begin
  puts "Try"
ensure
  puts "Cleanup"
rescue
  puts "Rescue"
end
ACode is correct and runs fine
BEnsure block cannot be used with rescue
CBegin block missing end keyword
DRescue block must come before ensure block
Step-by-Step Solution
Solution:
  1. Step 1: Review block order rules

    In Ruby, the rescue block must come before the ensure block.
  2. Step 2: Identify incorrect order

    This code places ensure before rescue, which is invalid syntax.
  3. Final Answer:

    Rescue block must come before ensure block -> Option D
  4. Quick Check:

    Rescue before ensure is required [OK]
Quick Trick: Order rescue before ensure in begin block [OK]
Common Mistakes:
  • Placing ensure before rescue
  • Assuming any order works
  • Ignoring syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes