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"?
<snip>

  ~ > 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
    #<NameError: (eval):1: undefined local variable or method `error' for #<Object:0x40190ce0>>

  eval(;|;|) caused
    #<SyntaxError: (eval):1: compile error
  (eval):1: parse error>

  eval(raise('badthings')) caused
    #<RuntimeError: (eval):1: badthings>


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
  ====================================