Bird
0
0

What does the rescue keyword do inside a begin/rescue/end block in Ruby?

easy📝 Conceptual Q1 of 15
Ruby - Error Handling
What does the rescue keyword do inside a begin/rescue/end block in Ruby?
AIt repeats the code inside the block
BIt defines a new method
CIt ends the program immediately
DIt catches and handles exceptions raised in the <code>begin</code> block
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of begin block

    The begin block contains code that might raise an error.
  2. Step 2: Understand what rescue does

    The rescue keyword catches exceptions raised in the begin block and allows handling them gracefully.
  3. Final Answer:

    It catches and handles exceptions raised in the begin block -> Option D
  4. Quick Check:

    Exception handling = A [OK]
Quick Trick: Use rescue to catch errors and prevent crashes [OK]
Common Mistakes:
  • Thinking rescue defines a method
  • Confusing rescue with program termination
  • Assuming rescue repeats code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes