#!/usr/bin/ruby filename = "test.rb" begin File.open(filename).each_line { |line| print line } rescue => ex if ex = Errno::ENOENT puts "We're sorry , we can't find your file now." else puts "I/O Exception with your file mate" end end