From: ahoward Date: 2003-03-31T15:13:15+09:00 Subject: Re: how to catch any exception "eval" throws On Mon, 31 Mar 2003, Meinrad Recheis wrote: > i tried > > begin > eval( str ) > rescue > puts $! > end > > but my program terminates if str contains erraneous expressions > why doesn t rescue catch say "parser errors"? ~ > cat foo.rb #!/usr/bin/env ruby %w[ error ;|;| raise('badthings') ].each do |badthing| begin eval badthing rescue NameError, SyntaxError, StandardError => err print "eval(#{badthing}) caused\n\t" p err print "\n" end end ~> ./foo.rb eval(error) caused #> eval(;|;|) caused # eval(raise('badthings')) caused # there are probably more to catch - but this is the bulk of them. -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================