Feature #7435

Exceptions should have backtrace_locations

Added by Sam Saffron over 1 year ago. Updated 8 months ago.

[ruby-core:50093]
Status:Rejected
Priority:Normal
Assignee:Koichi Sasada
Category:core
Target version:next minor

Description

Further to http://bugs.ruby-lang.org/issues/7051

def boom
raise "boom"
end

begin
boom
rescue => e
p e.backtrace
end

["t.rb:2:in boom'", "t.rb:6:in'"]

It seems exceptions still store backtraces in strings, shouldn't the backtrace be stored in RubyVM::Backtrace::Location objects and then optionally grabbed using backtrace_locations or backtrace depending on how you feel?

This means exceptions could be more efficient as filenames could easily be pinned in memory leading to significantly reduced allocation for exceptions.

History

#1 Updated by Sam Saffron over 1 year ago

ouch, this was meant to be a feature req not a bug ... cant figure out how to change

#2 Updated by Zachary Scott over 1 year ago

  • Tracker changed from Bug to Feature
  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to Koichi Sasada
  • Target version set to 2.0.0

#3 Updated by Zachary Scott over 1 year ago

  • Target version changed from 2.0.0 to next minor

Sorry, meant next minor, as #7051

#4 Updated by Koichi Sasada over 1 year ago

(2012/11/26 7:02), sam.saffron (Sam Saffron) wrote:

This means exceptions could be more efficient as filenames could easily be pinned in memory leading to significantly reduced allocation for exceptions.

Current implementation does not make String array.
Please run the following code:


def foo
raise
end

begin
foo
rescue => e
# e.backtrace # (X)
ObjectSpace.eachobject(Array){|ary|
if ary.find{|obj| obj.is
a?(String) and /foo/ =~ obj}
p ary
end
}
end


If you run (X), then the code prints out backtrace object.

--
// SASADA Koichi at atdot dot net

#5 Updated by Koichi Sasada over 1 year ago

  • Status changed from Assigned to Rejected

#6 Updated by Koichi Sasada over 1 year ago

One more comment.

Exception class has Exception#set_backtrace method, which set backtrace using string array. It conflicts with locations.

We need to solve this issue to support Exception#backtrace_locations.

#7 Updated by Charles Nutter about 1 year ago

I wish I had seen this before 2.0.0!

Perhaps setbacktrace should just cause backtracelocations to return an empty array?

I really, really wish backtrace_locations had gotten into 2.0.0, so let's try to make this happen for 2.1.

#8 Updated by Tsuyoshi Sawada 8 months ago

Why is this issue closed? Is this problem solved? I think it is a very important feature that is missing.

Also available in: Atom PDF