Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Exceptionクラス > backtrace

instance method Exception#backtrace

backtrace -> [String]

バックトレース情報を返します。

デフォルトでは

  • "#{sourcefile}:#{sourceline}:in `#{method}'" (メソッド内の場合)
  • "#{sourcefile}:#{sourceline}" (トップレベルの場合)

という形式の String の配列です。

def methd
  raise
end

begin
  methd
rescue => e
  p e.backtrace
end

#=> ["filename.rb:2:in `methd'", "filename.rb:6"]
class Exception