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

instance method Exception#backtrace

backtrace -> [String][permalink][rdoc]

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

デフォルトでは

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



def methd
  raise
end

begin
  methd
rescue => e
  p e.backtrace
end

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

[SEE_ALSO] Exception#backtrace_locations