Ruby Language Reference

rescue statement

Syntax

begin
  code
rescue StandardError
  expression
end

The rescue statement evaluates the expression if an exception (a subclass of StandardError) is raised during the execution of the code.

Rescue One Line Form

code rescue expression

For instance:

name = '' rescue nil

The name variable would be blank when we encounter nil.


Sharing is Caring