Project

General

Profile

Feature #7435

Exceptions should have backtrace_locations

Added by sam.saffron (Sam Saffron) over 4 years ago. Updated over 3 years ago.

Status:
Rejected
Priority:
Normal
Target version:
[ruby-core:50093]

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 [ruby-core:50095] Updated by sam.saffron (Sam Saffron) over 4 years ago

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

#2 [ruby-core:50103] Updated by zzak (Zachary Scott) over 4 years ago

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

#3 [ruby-core:50104] Updated by zzak (Zachary Scott) over 4 years ago

  • Target version changed from 2.0.0 to next minor

Sorry, meant next minor, as #7051

#4 [ruby-core:50107] Updated by ko1 (Koichi Sasada) over 4 years 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.each_object(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 [ruby-core:50111] Updated by ko1 (Koichi Sasada) over 4 years ago

  • Status changed from Assigned to Rejected

#6 [ruby-core:50521] Updated by ko1 (Koichi Sasada) over 4 years 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 [ruby-core:52595] Updated by headius (Charles Nutter) about 4 years ago

I wish I had seen this before 2.0.0!

Perhaps set_backtrace should just cause backtrace_locations 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 [ruby-core:56591] Updated by sawa (Tsuyoshi Sawada) over 3 years 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