Ruby 异常格式化输出:PrettyBacktrace

jopen 6年前

PrettyBacktrace 项目用于对 Ruby 的异常堆栈进行格式化显示,示例代码:

require 'pretty_backtrace'  PrettyBacktrace.enable     def recursive n    str = "Hi #{n}!!  " * 128    if n > 0      recursive n - 1    else      raise "bottom of recursive"    end  end     recursive 3

格式化效果:

test.rb:10:in `recursive' (n = 0, str = "Hi 0!!  Hi 0!!  Hi 0...): bottom of recursive (RuntimeError)
        from test.rb:9:in `recursive' (n = 1, str = "Hi 1!!  Hi 1!!  Hi 1...)
        from test.rb:9:in `recursive' (n = 2, str = "Hi 2!!  Hi 2!!  Hi 2...)
        from test.rb:9:in `recursive' (n = 3, str = "Hi 3!!  Hi 3!!  Hi 3...)
        from test.rb:15:in `<main>'

项目主页:http://www.open-open.com/lib/view/home/1423662383498