Bird
0
0

Which of the following best describes how the rescue modifier works in Ruby?

easy📝 Conceptual Q2 of 15
Ruby - Error Handling
Which of the following best describes how the rescue modifier works in Ruby?
AIt executes the code after rescue only if an exception occurs
BIt always executes the code after rescue regardless of errors
CIt prevents the program from running any code after rescue
DIt converts exceptions into warnings
Step-by-Step Solution
Solution:
  1. Step 1: Analyze rescue modifier behavior

    The code after rescue runs only if an exception happens in the preceding expression.
  2. Step 2: Eliminate incorrect options

    It always executes the code after rescue regardless of errors is wrong because rescue code runs only on error, not always. It prevents the program from running any code after rescue and D describe unrelated behaviors.
  3. Final Answer:

    It executes the code after rescue only if an exception occurs -> Option A
  4. Quick Check:

    Rescue modifier runs fallback only on error [OK]
Quick Trick: Rescue code runs only when an error happens [OK]
Common Mistakes:
  • Assuming rescue code runs every time
  • Thinking rescue suppresses warnings instead of errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes