begin : rescue « Statement « Ruby






begin

    names=IO.readlines("C:\\customer_details1.txt")
    count=names.length
    for i in 0...count
         puts "The contents of the file are #{names[i]}"
    end
    rescue
         $stderr.puts "error"
         puts "The error occurred is #{$!}"
end

 








Related examples in the same category

1.rescue's syntax makes handling different exceptions in different ways easy:
2.C++, Java, and Ruby exception handling compared
3.how exceptions work in Ruby.
4.Handling Exceptions: 10 / 0
5.Handling Passed Exceptions