ruby-uebungen/Assignment_026/solution/readme.md

19 lines
534 B
Markdown
Raw Normal View History

2023-05-25 17:47:19 +02:00
# Lösung: Ausnahmen
2023-05-23 09:19:31 +02:00
2023-05-25 17:47:19 +02:00
<div style="border: 1px solid grey;"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>```ruby
def division(a, b)
raise ArgumentError unless (a.is_a? Numeric) && (b.is_a? Numeric)
raise ZeroDivisionError if b == 0
a / b
2023-05-23 09:19:31 +02:00
end
2023-05-25 17:47:19 +02:00
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
```