Ruby 异常格式化输出 PrettyBacktrace

MIT
Ruby
跨平台
2015-02-11
红薯

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>'

加载中

评论(0)

暂无评论

暂无资讯

暂无问答

暂无博客

返回顶部
顶部