Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Error Handling
Identify the error in this Ruby code:
class MyError < StandardError
end

begin
  raise MyError, "Error occurred"
rescue MyError => e
  puts e.message
end
AIncorrect inheritance syntax
BMissing 'end' keyword after class definition
CNo error, code runs fine
DWrong rescue syntax
Step-by-Step Solution
Solution:
  1. Step 1: Check class definition syntax

    The class definition has a proper 'end' keyword to close it.
  2. Step 2: Confirm other parts

    Inheritance and rescue syntax are correct, so there is no error.
  3. Final Answer:

    No error, code runs fine -> Option C
  4. Quick Check:

    Class properly closed with 'end' [OK]
Quick Trick: Always close class with 'end' [OK]
Common Mistakes:
  • Forgetting 'end' after class
  • Confusing inheritance syntax
  • Miswriting rescue block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes