On my machine (Windows 2000), this problem indeed occurs with Ruby 1.6.6 and
1.6.7.
The error is caugth correctly with Ruby 1.7.2.

"Michael Davis" <mdavis / sevainc.com> wrote in message
news:3C8BB669.7060303 / sevainc.com...
> I need to be able to trap error during a call to instance_eval.  Here is
> a code snip-it that closely resembles what I am trying to do.  This
> errors but never hits the rescue clause.  Any idea how to trap an error
> inside a call to instance_eval?
>
> a = [1,2]
> begin
>    a.instance_eval('puts a2.inspect')
> rescue
>    puts 'error'
> end
>
>
> I was expecting to see:
>
>      error
>
> however, this little program outputs the following:
>
> Exception `NameError' at (eval):1 - undefined local variable or method
> `a2' for [1, 2]:Array
> Exception `NameError' at ../test.rb:3 - (eval):1:in `instance_eval':
> undefined local variable or method `a2' for [1, 2]:Array
> ./test.rb:3:in `instance_eval': (eval):1:in `instance_eval': undefined
> local variable or method `a2' for [1, 2]:Array (NameError)
>          from ../test.rb:3:in `instance_eval'
>          from ../test.rb:3
>
>
> I am running Ruby 1.6.5 on Windows 2000 with the latest version of cygwin.
>
> --
> Thanks, Michael Davis
> Database Architect and Senior Software Engineer, Seva Inc.
> Email: mdavis / sevainc.com
>
>