how exceptions work in Ruby. : rescue « Statement « Ruby






how exceptions work in Ruby.


begin
    eval "12 / 0"
rescue ZeroDivisionError
    puts "Oops. You tried to divide by zero again."
    exit 1
ensure
    puts "Tsk. Tsk."
end

 








Related examples in the same category

1.rescue's syntax makes handling different exceptions in different ways easy:
2.C++, Java, and Ruby exception handling compared
3.Handling Exceptions: 10 / 0
4.Handling Passed Exceptions
5.begin