Exception Handling • Exercise 1/4

Basic Rescue

00:00
0
15 points

Instructions

Create a function safe_divide that divides two numbers.
If division by zero occurs, return nil instead of raising an error.

Use begin/rescue to catch exceptions:
ruby
begin
# risky code
rescue ZeroDivisionError
# handle error
end

Your Code

Results

Click "Run Tests" to see results