From: 7stud -- Date: 2007-09-19T06:16:37+09:00 Subject: Re: removing newline from eachline in file Chuck Dawit wrote: > Also if the url doesn't work/exist > I don't want the script to crash I want to keep moving through the file > its reading. > > begin > while (line = f.readline) > line = line =~ /(.*?)\n/ > url = "www." + line + ".net" > > open(url) { |page| page_content = page.read() > puts "link exists" > } > end > rescue > puts "link does not exist" > > rescue EOFError > f.close > end If your program is currently crashing on bad urls, you just need to put the begin/rescue around the open statement---not outside your loop. Something like this(untested): begin while (line = f.readline) line = line =~ /(.*?)\n/ url = "www." + line + ".net" begin open(url) { |page| page_content = page.read() } puts "link exists" rescue Exception puts "in rescue" #do nothing -- when you catch an exception the exception goes away puts "execution continues on its way" end end -- Posted via http://www.ruby-forum.com/.