0Pricing
Ruby Academy · Lesson

Handling Errors with begin and rescue

Prevent crashes by catching and handling errors with exception handling.

1

Handling Errors with begin and rescue

Errors are inevitable in programming, but Ruby provides mechanisms to handle them gracefully.

In this lesson, you will learn how to use begin and rescue to catch and handle exceptions.

Handling Errors with begin and rescue — illustration 1

2

Using begin and rescue

Use begin and rescue to catch and handle errors.

begin
  puts 10 / 0
rescue ZeroDivisionError
  puts 'Cannot divide by zero!'
end

All lessons in this course

  1. Handling Errors with begin and rescue
  2. Raising and Customizing Exceptions
  3. Debugging Techniques
← Back to Ruby Academy