From: Paul Brannan Date: 2001-10-03T23:07:51+09:00 Subject: [ruby-talk:22002] Backtrace with eval I've noticed that when I use eval, I get a backtrace that is very un-useful. Consider this program: def foo raise "foo!" end def bar foo end def do_test begin proc.call rescue Exception puts $!, $!.backtrace end end do_test do eval "bar" end do_test do __send__ "bar" end The first do_test block (using eval) gives me: bt.rb:2:in `foo': foo! bt.rb:18 bt.rb:18:in `eval' bt.rb:18 bt.rb:18:in `call' bt.rb:11:in `do_test' bt.rb:18 And the second do_test block (using __send__) gives me: foo! bt.rb:2:in `foo' bt.rb:6:in `bar' bt.rb:24:in `__send__' bt.rb:24 bt.rb:24:in `call' bt.rb:11:in `do_test' bt.rb:24 Questions: 1) Why does eval not give me a proper backtrace? (I would much prefer to use eval over __send__, since security/speed are not issues for what I'm writing, and eval doesn't allow me to do evil things like call private methods in objects that I don't have access to). 2) Why does using eval give me "bt.rb:2:in `foo': foo!" while using __send__ gives me "foo!\nbt.rb:2:in `foo'"? This seems a little inconsistent. 3) What's with the blank lines "bt.rb:18" and "bt.rb:24"? Thanks, Paul