From: Xeno Campanoli Date: 2005-06-08T08:20:00+09:00 Subject: Re: Rescue just won't work for me on SuSE Ghislain Mary wrote: > Hi, > > Xeno Campanoli a �crit : > >> I can't figure out Rescue. I have the following: >> >> rescue SystemCallError >> print "parse failed on #{line}" + $! >> raise >> end >> >> and it doesn't compile: >> >> /validateMenuSpecs.rb:135: syntax error >> rescue SystemCallError >> ^ >> ./validateMenuSpecs.rb:135: warning: useless use of a constant in >> void context >> ./validateMenuSpecs.rb:173: syntax error >> > > You must have a context has the warning message tells you. So you must > have something like > > begin > # do something here > rescue SystemCallError > print "parse failed on #{ line}" + $! > raise > end I tried this: TargetsCategoriesFH.each_line do |line| begin target, catlist = line.chomp.strip.split(/\s*:\s*/) rescue NoMethodError #print "parse failed on #{line}" + $! print "parse failed " + $! raise end . . . end and I get ./validateMenuSpecs.rb:152: private method `chomp' called for nil:NilClass (NoMethodError) from ./validateMenuSpecs.rb:132:in `each_line' from ./validateMenuSpecs.rb:132 with the rescue code commented out, I get: ./validateMenuSpecs.rb:153: private method `chomp' called for nil:NilClass (NoMethodError) from ./validateMenuSpecs.rb:132:in `each_line' from ./validateMenuSpecs.rb:132 Again. > > You should then put the code that you expect to get an exception from > after the begin clause. > > HTH > > Ghislain > > > -- Xeno Campanoli, xeno@eskimo.com, http://www.eskimo.com/~xeno Pride before justice equals destabilization. Power before truth equals destruction. Profit before environment equals death.