Ruby Language Reference

begin statement

Syntax

begin
  code
rescue exception_class1, exception_class2 => variable
  code
else
  code
ensure
  code
end

The begin statement encloses code and performs exception handling when used with the rescue and ensure clauses. When a rescue clauses catches the exception that matches any of the exceptions in the list, the code within the rescue block is executed. If a variable is specified, the exception object is stored in it. If no exceptions occur, the else clause is executed, if specified. If an ensure clause is specified, its code is always executed before the begin-end block exits, regardless of whether an exception occurred or not.


Sharing is Caring