Bird
0
0

You want to catch all exceptions except system-exiting ones like SystemExit and Interrupt. Which class should you rescue to catch most errors but allow system exits?

hard📝 Application Q15 of 15
Ruby - Error Handling

You want to catch all exceptions except system-exiting ones like SystemExit and Interrupt. Which class should you rescue to catch most errors but allow system exits?

AStandardError
BException
CRuntimeError
DNoMethodError
Step-by-Step Solution
Solution:
  1. Step 1: Understand exception classes for system exit

    Classes like SystemExit and Interrupt inherit directly from Exception, not StandardError.
  2. Step 2: Choose rescue class to exclude system exits

    Rescuing StandardError catches most runtime errors but excludes system-exiting exceptions.
  3. Step 3: Confirm other options

    Rescuing Exception catches everything including system exits, which is usually not desired.
  4. Final Answer:

    StandardError -> Option A
  5. Quick Check:

    Rescue StandardError to exclude system exits [OK]
Quick Trick: Rescue StandardError to avoid catching system exits [OK]
Common Mistakes:
  • Rescuing Exception catches system exits too
  • Choosing RuntimeError misses some errors
  • Confusing NoMethodError as base class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes