Catching line numbers in ruby exceptions

后端 未结 5 548
孤独总比滥情好
孤独总比滥情好 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:52

    Usually the backtrace contains a lot of lines from external gems It's much more convenient to see only lines related to the project itself

    My suggestion is to filter the backtrace by the project folder name

    puts e.backtrace.select { |x| x.match(/HERE-IS-YOUR-PROJECT-FOLDER-NAME/) }
    

    And then you can parse filtered lines to extract line numbers as suggested in other answers.

提交回复
热议问题