Project

General

Profile

Actions

Feature #8960

open

Add Exception#backtrace_locations

Feature #8960: Add Exception#backtrace_locations

Added by headius (Charles Nutter) about 12 years ago. Updated almost 9 years ago.

Status:
Assigned
Target version:
-
[ruby-core:57430]

Description

All parties agreed this would be useful to add in https://bugs.ruby-lang.org/issues/7895 and ko1 suggested I file a feature against ruby-trunk. So here it is.

I might be able to come up with a patch, but I'm not sure when. Help wanted.

Can we agree this will go into 2.1?


Related issues 1 (1 open0 closed)

Related to Ruby - Feature #7895: Exception#backtrace_locations to go with Thread#backtrace_locations and Kernel#caller_locationsOpenActions

Updated by ko1 (Koichi Sasada) about 12 years ago Actions #1 [ruby-core:57470]

  • Category set to core
  • Assignee set to ko1 (Koichi Sasada)
  • Target version set to 2.1.0

I'll try before preview-2.

JRuby already has a implementation and tests?

Updated by headius (Charles Nutter) about 12 years ago Actions #2 [ruby-core:57489]

JRuby has implementation but no tests. The test should look pretty much like Thread#backtrace_locations tests, though.

I can work on some tests if you work on impl for MRI.

Updated by nobu (Nobuyoshi Nakada) almost 12 years ago Actions #3 [ruby-core:59082]

What will be returned from an exception set by Exception#set_backtrace in JRuby?

Updated by ko1 (Koichi Sasada) almost 12 years ago Actions #4

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r44170.
Charles, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • error.c: add Exception#backtrace_locations.
    Now, there are no setter and independent from Exception#backtrace.
    [Feature #8960]
  • eval.c (setup_exception): set backtrace locations for `bt_location'
    special attribute.
  • vm_backtrace.c (rb_backtrace_to_location_ary): added.
  • internal.h: ditto.
  • test/ruby/test_backtrace.rb: add a test for
    Exception#backtrace_locations.

Updated by ko1 (Koichi Sasada) almost 12 years ago Actions #5 [ruby-core:59084]

  • Status changed from Closed to Feedback
  • Target version changed from 2.1.0 to 2.6
  • % Done changed from 100 to 0

Now, I implemented half-baked feature (read-only backtrace locations).

How about to continue how to change it?

Updated by headius (Charles Nutter) almost 12 years ago Actions #6 [ruby-core:59381]

ko1: I have no problem whatsoever with backtrace_locations being read-only now and forever. I'm glad to see this made it into 2.1 as at least a basic feature.

Updated by ryannevell (Ryan Nevell) about 9 years ago Actions #7 [ruby-core:76954]

  • Assignee changed from ko1 (Koichi Sasada) to headius (Charles Nutter)

Is there any way to re-raise an exception and propagate backtrace_locations? When I want to trap an exception and provide a different exception class and error message, I'm used to doing something like:

rescue => e
  raise MyCustomException, "Error details", e.backtrace

But this is calling set_backtrace, leaving the resulting exception's backtrace_locations nil (on MRI 2.3.1) or and empty array (on jruby 9.1.2.0).

If only some exceptions will have a valid backtrace_locations array (matching the information in backtrace), it is difficult to write code that takes advantage of this feature.

Updated by nobu (Nobuyoshi Nakada) about 9 years ago Actions #8 [ruby-core:76957]

Ryan Nevell wrote:

Is there any way to re-raise an exception and propagate backtrace_locations? When I want to trap an exception and provide a different exception class and error message, I'm used to doing something like:

Nothing right now.

If only some exceptions will have a valid backtrace_locations array (matching the information in backtrace), it is difficult to write code that takes advantage of this feature.

Agree.

Updated by shyouhei (Shyouhei Urabe) almost 9 years ago Actions #9 [ruby-core:78343]

  • Status changed from Feedback to Assigned
  • Assignee changed from headius (Charles Nutter) to ko1 (Koichi Sasada)

Updated by shyouhei (Shyouhei Urabe) almost 9 years ago Actions #10 [ruby-core:78361]

We looked at this issue today. It turned out that ruby do not fully implement what was needed originally now. Reopened the ticket to assign ko1.

Actions

Also available in: PDF Atom