Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Error Handling
What will be the output of this Ruby code?
value = 10 / 0 rescue 'division error'
puts value
Adivision error
B0
CInfinity
DRuntimeError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the division operation

    Dividing 10 by 0 raises a ZeroDivisionError exception in Ruby.
  2. Step 2: Apply rescue modifier

    The rescue modifier catches the exception and returns the string 'division error'.
  3. Final Answer:

    division error -> Option A
  4. Quick Check:

    Rescue returns fallback on error = 'division error' [OK]
Quick Trick: Division by zero triggers rescue fallback [OK]
Common Mistakes:
  • Expecting zero or Infinity instead of rescue fallback
  • Confusing rescue with exception propagation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes