0
0

More than 3 years have passed since last update.

Ruby学習#28 Handling Errors

Posted at

lucky_nums = [4,8,15,16,23.42]

lucky_nums["dog"]

into Integer(Typeerror)

begin
num = 10 / 0
rescue
puts "Division by zero error "
end

Division by zero error

begin
lucky_nums["dog"]
num = 10 / 0
rescue ZeroDivisionError
puts "Division by zero error "
rescue TypeError => e
puts e
end

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0