From: Robert Klemme Date: 2010-08-27T22:07:01+09:00 Subject: Re: error handling with exceptions in multi-thread download 2010/8/27 Pen Ttt : > >    there are three  program fragments,all of them  have same problems, >    all  of them  can run ,but when i downloaded  30% data,an error > ocurr >    undefined local variable or method `web' for Data:Class (NameError) You need to look into class methods of class Data. Somewhere there you will find usage of "web" which is undefined. Unfortunately you did not post that class so we cannot tell you where your error is. >    cthreaddown  is an  array  which contains many web. >    would you kind to tell  me how to fix  it? >    p1 >     [code] >     for page_to_fetch in cthreaddown >     threads<         datafile="/home/pt/stock/" >         open(datafile,'a+'){|refile| >         open(web){|webfile| >              refile.puts  webfile.read You should use #write with #read and not #puts, because #puts does not write out arguments unmodified. Also note that if webfile is large this approach will break. You should better use blocked reading. buffer = "" while webfile.read(1024, buffer) refile.write buffer end >              puts  "#{web}  is over" >         }} >        end >      end >     threads.each {|thr| >        begin >         thr.join >         rescue Timeout::Error => e >           puts    "#{web}  failed" >         rescue NameError => e >           puts    "#{web}  failed" >         rescue => e >           puts    "#{web}  failed" >        end >       } >      [/code] Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/