すでに別の関数が用意されていそうな気もする。
def format_exception(e) backtrace = e.backtrace head = "#{backtrace.first}: #{e.message} (#{e.class})" rest = backtrace.slice(1..-1).map {|i| "\tfrom #{i}" } ([head] + rest).join($/) end def foo raise 'xxxxx' end def bar foo end begin foo rescue => e puts format_exception(e) raise e end
C:/eclipse/workspace/rails_async_callback_runner/vendor/plugins/foo.rb:9:in `foo': xxxxx (RuntimeError)
from C:/eclipse/workspace/rails_async_callback_runner/vendor/plugins/foo.rb:17
C:/eclipse/workspace/rails_async_callback_runner/vendor/plugins/foo.rb:9:in `foo': xxxxx (RuntimeError)
from C:/eclipse/workspace/rails_async_callback_runner/vendor/plugins/foo.rb:17