本文簡要介紹ruby語言中 Exception.backtrace
的用法。
用法
backtrace → array or nil
返回與異常關聯的任何回溯。回溯是一個字符串數組,每個字符串包含“filename:lineNo: in ‘method”’或“filename:lineNo.”
def a
raise "boom"
end
def b
a()
end
begin
b()
rescue => detail
print detail.backtrace.join("\n")
end
產生:
prog.rb:2:in `a' prog.rb:6:in `b' prog.rb:10
如果沒有設置回溯,則返回nil
ex = StandardError.new
ex.backtrace
#=> nil
相關用法
- Ruby Exception類用法及代碼示例
- Ruby Extend類用法及代碼示例
- Ruby ERB.location=用法及代碼示例
- Ruby Enumerable.any?用法及代碼示例
- Ruby Enumerable min_by()用法及代碼示例
- Ruby Enumerable each_witth_object()用法及代碼示例
- Ruby ErrorHighlight.spot用法及代碼示例
- Ruby Enumerable.slice_before用法及代碼示例
- Ruby Enumerable each_cons()用法及代碼示例
- Ruby Enumerator each_with_index用法及代碼示例
- Ruby Encoding.compatible?用法及代碼示例
- Ruby Enumerable.uniq用法及代碼示例
- Ruby Enumerator each_with_object用法及代碼示例
- Ruby ERBIO類用法及代碼示例
- Ruby ENV.empty?用法及代碼示例
- Ruby Enumerable uniq()用法及代碼示例
- Ruby Enumerable.find_all用法及代碼示例
- Ruby Enumerator.peek_values用法及代碼示例
- Ruby Enumerable.max用法及代碼示例
- Ruby Enumerable.map用法及代碼示例
- Ruby Enumerable min()用法及代碼示例
- Ruby Enumerable.min_by用法及代碼示例
- Ruby Enumerable.find_index用法及代碼示例
- Ruby Enumerator類用法及代碼示例
- Ruby Enumerable find_index()用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Exception.backtrace。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。