ruby-uebungen/Assignment_026/solution
Thomas Smits 58bc23516c Update of exercises 2023-05-25 17:49:42 +02:00
..
readme.md Update of exercises 2023-05-25 17:49:42 +02:00

readme.md

Lösung: Ausnahmen

def division(a, b)
  raise ArgumentError  unless (a.is_a? Numeric) && (b.is_a? Numeric)
  raise ZeroDivisionError  if b == 0
  a / b
end

begin
  puts division(1.0, 4.0)
  puts division(1.0, 0.0)
  puts division('a', 7)
rescue ArgumentError => e
  puts e
rescue ZeroDivisionError => e
  puts e
end