Catching line numbers in ruby exceptions

后端 未结 5 554
孤独总比滥情好
孤独总比滥情好 2021-01-30 16:21

Consider the following ruby code

test.rb:

begin

  puts
  thisFunctionDoesNotExist
  x = 1+1
rescue Exception => e
  p e
end

For deb

5条回答
  •  长发绾君心
    2021-01-30 16:43

    It is possible that in Ruby 1.9.3 you will be able to get access to not only this information in a more structured, reliable, and simpler way without using regular expressions to cut strings.

    The basic idea is to introduce a call frame object which gives access to information about the call stack.

    See http://wiki.github.com/rocky/rb-threadframe/, which alas, requires patching Ruby 1.9. In RubyKaigi 2010 (late August 2010) a meeting is scheduled to discuss introducing a frame object into Ruby.

    Given this, the earliest this could happen is in Ruby 1.9.3.

提交回复
热议问题