Bird
0
0

You want to rescue only exceptions related to file operations but not all standard errors. Which class should you rescue in Ruby?

hard📝 Application Q8 of 15
Ruby - Error Handling
You want to rescue only exceptions related to file operations but not all standard errors. Which class should you rescue in Ruby?
AStandardError
BIOError
CException
DRuntimeError
Step-by-Step Solution
Solution:
  1. Step 1: Identify file operation related exceptions

    File operation errors in Ruby are subclasses of IOError.
  2. Step 2: Choose rescue class to catch only file errors

    Rescuing IOError catches only file-related exceptions, not all standard errors.
  3. Final Answer:

    IOError -> Option B
  4. Quick Check:

    Rescue IOError for file-related exceptions only [OK]
Quick Trick: IOError covers file-related exceptions specifically [OK]
Common Mistakes:
  • Rescuing StandardError catches too many exceptions
  • Using Exception rescues all exceptions including system
  • Confusing RuntimeError with IOError

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes