Bird
0
0

Why is it important to specify the exception class in a rescue clause in Ruby?

hard📝 Conceptual Q10 of 15
Ruby - Error Handling
Why is it important to specify the exception class in a rescue clause in Ruby?
ATo make the program run faster
BTo catch only specific errors and avoid hiding unexpected bugs
CTo automatically retry the code block
DTo skip the <code>begin</code> block entirely
Step-by-Step Solution
Solution:
  1. Step 1: Understand rescue behavior without exception class

    Rescuing without specifying catches all exceptions, which can hide bugs.
  2. Step 2: Benefit of specifying exception class

    Specifying exception class catches only expected errors, making debugging easier and safer.
  3. Final Answer:

    To catch only specific errors and avoid hiding unexpected bugs -> Option B
  4. Quick Check:

    Specific rescue prevents hidden bugs = B [OK]
Quick Trick: Specify exceptions to avoid hiding bugs [OK]
Common Mistakes:
  • Thinking it speeds up code
  • Assuming it retries code
  • Believing it skips begin block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes