zaagan
1/27/2020 - 5:58 PM

Ruby Basics - Exception Handling

Ruby Basics - Exception Handling

# Example 1
begin
  x = 5 / 0
rescue
  puts "Ohh no !!!"
ensure
  puts "This will always execute"
end

# Example 2
begin
  x = 5 / 0
rescue ZeroDivisionError
  puts "Did you just divid by a zero ??"
end

# Example 3
begin
  x = 5 / 0
rescue Exception => ex
  puts ex.message
end