Bird
0
0

Which of the following is the correct way to rescue an exception in Ruby using begin/rescue/end?

easy📝 Syntax Q3 of 15
Ruby - Error Handling
Which of the following is the correct way to rescue an exception in Ruby using begin/rescue/end?
A<pre>begin # code rescue SomeError # handle error end</pre>
B<pre>try # code catch SomeError # handle error end</pre>
C<pre>begin # code catch SomeError # handle error end</pre>
D<pre>try # code rescue SomeError # handle error end</pre>
Step-by-Step Solution
Solution:
  1. Step 1: Identify Ruby syntax for exception handling

    Ruby uses begin/rescue/end blocks, not try/catch.
  2. Step 2: Check each option

    Only
    begin
      # code
    rescue SomeError
      # handle error
    end
    uses correct Ruby keywords begin and rescue.
  3. Final Answer:

    begin # code rescue SomeError # handle error end -> Option A
  4. Quick Check:

    Ruby uses begin/rescue/end, not try/catch [OK]
Quick Trick: Ruby uses begin/rescue/end, not try/catch [OK]
Common Mistakes:
  • Confusing Ruby with other languages using try/catch
  • Using catch instead of rescue in Ruby

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes