Is there any way to start the Ruby debugger on exception?

前端 未结 5 1125
温柔的废话
温柔的废话 2020-12-28 09:21

Is there any way to start the/a Ruby debugger whenever the code throws an exception, without me wrapping the code like this:

begin
  #do something
rescue
  d         


        
相关标签:
5条回答
  • 2020-12-28 09:31

    In RubyMine 2.0.x go to Run -> View Breakpoints and click "Ruby Exception Breakpoints" tab, then add the type of the exception you are interested in...

    There should be something similar in NetBeans and other Ruby IDEs i guess.

    BTW, RubyMine is the BEST!

    0 讨论(0)
  • 2020-12-28 09:43

    I stumbled across this page:post-mortem debugging. Doing this:

    Debugger.start(:post_mortem => true)
    

    gets me where I want to.

    0 讨论(0)
  • 2020-12-28 09:47
    require 'ruby-debug'
    class Exception
      alias original_initalize initialize
      def initialize(*args)
        original_initalize(*args)
        debugger
      end
    end
    

    This will run the original exception as well as call debugger

    0 讨论(0)
  • 2020-12-28 09:47

    if you're using ruby-debug (and it looks like you are), you can set catchPoints for the exception you want.

     (rdbg) catch Exception
    

    for example

    0 讨论(0)
  • 2020-12-28 09:50

    Hammertime!

    0 讨论(0)
提交回复
热议问题