This the ruby code which is equivalent of a try/catch/finally block in other languages.
begin
somecode()
rescue
puts “Error #{$!}”
ensure
this_code_will_execute_always()
end
# Sample Code
f = File.open(“testfile.txt”)
begin
# .. process
rescue
# .. handle error
else
puts “– no errors!”
ensure
f.close unless f.nil?
end