Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Error Handling
Find the error in this Ruby code:
begin
  puts 10 / 2
rescue ZeroDivisionError
  puts "Error"
ADivision by zero error not handled
BWrong exception class in rescue
CMissing <code>end</code> keyword to close the block
Dputs syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check block structure

    The begin block is not closed with end, causing syntax error.
  2. Step 2: Verify other parts

    Exception class and puts syntax are correct; division is safe here.
  3. Final Answer:

    Missing end keyword to close the block -> Option C
  4. Quick Check:

    Block must end with end = A [OK]
Quick Trick: Always close begin/rescue with end [OK]
Common Mistakes:
  • Forgetting end keyword
  • Using wrong exception class
  • Miswriting puts statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes