Ruby 2.1.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Exceptionクラス > backtrace_locations
backtrace_locations -> [Thread::Backtrace::Location]
[permalink][rdoc]バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
現状では Exception#set_backtrace によって戻り値が変化する事はありません。
require "date"
def check_long_month(month)
return if Date.new(2000, month, -1).day == 31
raise "#{month} is not long month"
end
def get_exception
return begin
yield
rescue => e
e
end
end
e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get_exception'", "test.rb:15:in `<main>'"]
[SEE_ALSO] Exception#backtrace