Bird
0
0

Find the problem in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - Error Handling
Find the problem in this Ruby code:
begin
  raise
rescue
  puts 'Error rescued'
end
Araise without argument outside rescue causes error
BNo error, code works correctly
Crescue without exception class is invalid
Dputs statement is unreachable
Step-by-Step Solution
Solution:
  1. Step 1: Understand raise without argument

    Using raise without arguments re-raises the last exception inside a rescue block.
  2. Step 2: Check context of raise

    Here, raise is called outside any rescue block, so it causes a RuntimeError.
  3. Final Answer:

    raise without argument outside rescue causes error -> Option A
  4. Quick Check:

    raise without argument needs rescue context [OK]
Quick Trick: raise without argument only works inside rescue blocks [OK]
Common Mistakes:
  • Assuming raise always works without argument
  • Thinking rescue without class is invalid
  • Ignoring context of raise usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes