throw catch

suggest change

Unlike many other programming languages, the throw and catch keywords are not related to exception handling in Ruby.

In Ruby, throw and catch act a bit like labels in other languages. They are used to change the control flow, but are not related to a concept of “error” like Exceptions are.

catch(:out) do
  catch(:nested) do
    puts "nested"
  end

  puts "before"
  throw :out
  puts "will not be executed"
end
puts "after"
# prints "nested", "before", "after"

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents