Project

General

Profile

Backport #1593

Exception backtrace within eval lacks topmost function

Added by chowlett (Chris Howlett) over 10 years ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
[ruby-core:23768]

Description

=begin
Hi,

I have a code snippet which uses eval to execute a Ruby fragment, protected with begin...rescue. If I attempt to display the exception backtrace within the rescue branch, the topmost line of context is missing. For instance:

except.rb:
def foo()
bar()
end

def bar()
baz()
end

def baz()
raise "Boom"
end

puts "Direct call."
begin
foo
rescue => e
puts e.backtrace
end

puts "\nThrough eval."
begin
eval "foo"
rescue => e
puts e.backtrace
end

Running this code produces:
\lib>except.rb
Direct call.
/lib/except.rb:10:in baz'
/lib/except.rb:6:in
bar'
/lib/except.rb:2:in `foo'
/lib/except.rb:15

Through eval.
/lib/except.rb:22
/lib/except.rb:6:in bar'
/lib/except.rb:2:in
foo'
(eval):1

Note that in the eval case, `baz' is not present in the backtrace.
=end

History

#1

Updated by ujihisa (Tatsuhiro Ujihisa) almost 10 years ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

=begin

=end

#2

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

  • ruby -v deleted (ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32])
  • Status changed from Assigned to Closed
  • Description updated (diff)
  • Project changed from Ruby 1.8 to Backport187
  • Tracker changed from Bug to Backport

Also available in: Atom PDF