Bird
0
0

You want to handle IOError and ZeroDivisionError differently but also catch any other exceptions generically. Which rescue clause order is correct?

hard📝 Application Q8 of 15
Ruby - Error Handling
You want to handle IOError and ZeroDivisionError differently but also catch any other exceptions generically. Which rescue clause order is correct?
Arescue StandardError rescue IOError, ZeroDivisionError
Brescue StandardError rescue IOError rescue ZeroDivisionError
Crescue IOError, ZeroDivisionError rescue StandardError
Drescue IOError rescue ZeroDivisionError rescue StandardError
Step-by-Step Solution
Solution:
  1. Step 1: Understand rescue clause order importance

    Specific exceptions must be rescued before generic exceptions.
  2. Step 2: Identify correct order

    rescue IOError rescue ZeroDivisionError rescue StandardError rescues IOError and ZeroDivisionError first, then generic StandardError last.
  3. Final Answer:

    rescue IOError rescue ZeroDivisionError rescue StandardError -> Option D
  4. Quick Check:

    Specific before generic rescue clauses [OK]
Quick Trick: Place specific rescues before generic ones [OK]
Common Mistakes:
  • Putting generic rescue first
  • Combining exceptions incorrectly
  • Misordering rescue clauses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes