Bird
0
0

What does the retry keyword do in Ruby when used inside a rescue block?

easy📝 Conceptual Q11 of 15
Ruby - Error Handling
What does the retry keyword do in Ruby when used inside a rescue block?
AIt skips the current error and continues after the <code>rescue</code> block.
BIt restarts the code inside the <code>begin</code> block from the beginning.
CIt stops the program immediately without handling the error.
DIt logs the error and moves to the next line of code.
Step-by-Step Solution
Solution:
  1. Step 1: Understand retry usage context

    The retry keyword is used inside a rescue block to repeat the code in the begin block.
  2. Step 2: Effect of retry

    When an error occurs and retry is called, Ruby restarts the begin block from the start, trying again.
  3. Final Answer:

    It restarts the code inside the begin block from the beginning. -> Option B
  4. Quick Check:

    retry restarts code = A [OK]
Quick Trick: Retry restarts the begin block after an error [OK]
Common Mistakes:
  • Thinking retry skips the error without retrying
  • Assuming retry stops the program
  • Confusing retry with error logging

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes