如何获得红宝石打印一个完整的追溯而不是截断的? [英] How do I get ruby to print a full backtrace instead of a truncated one?
本文介绍了如何获得红宝石打印一个完整的追溯而不是截断的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我收到异常时,通常来自调用堆栈的深处。当这种情况发生时,通常情况下,实际的违规代码行是隐藏的:
When I get exceptions, it is often from deep within the call stack. When this happens, more often than not, the actual offending line of code is hidden from me:
tmp.rb:7:in `t': undefined method `bar' for nil:NilClass (NoMethodError)
from tmp.rb:10:in `s'
from tmp.rb:13:in `r'
from tmp.rb:16:in `q'
from tmp.rb:19:in `p'
from tmp.rb:22:in `o'
from tmp.rb:25:in `n'
from tmp.rb:28:in `m'
from tmp.rb:31:in `l'
... 8 levels...
from tmp.rb:58:in `c'
from tmp.rb:61:in `b'
from tmp.rb:64:in `a'
from tmp.rb:67
那个... 8级... 截断造成我很大的麻烦。我没有太多的成功搜索这一个:如何告诉红宝石,我想要转储包括完整的堆栈?
That "... 8 levels..." truncation is causing me a great deal of trouble. I'm not having much success googling for this one: How do I tell ruby that I want dumps to include the full stack?
推荐答案
p>异常#backtrace有整个堆栈:
Exception#backtrace has the entire stack in it:
def do_division_by_zero; 5 / 0; end
begin
do_division_by_zero
rescue => exception
puts exception.backtrace
raise # always reraise
end
(由Peter Cooper的 Ruby Inside 博客启发)
(Inspired by Peter Cooper's Ruby Inside blog)
这篇关于如何获得红宝石打印一个完整的追溯而不是截断的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文