Skip to content

Instantly share code, notes, and snippets.

@alex-handley
Created March 15, 2013 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-handley/5173776 to your computer and use it in GitHub Desktop.
Save alex-handley/5173776 to your computer and use it in GitHub Desktop.
A exception wrapper to collect both stack traces. e.g. this error was thrown here -- WRAPPED BACKTRACE -- the original error was thrown there Source: http://www.drmaciver.com/2013/03/a-manifesto-for-error-reporting/
class A
def self.b
begin
raise TypeError
rescue => e
raise MyLibrarySpecificException.new(e)
end
end
end
class MyLibrarySpecificException < StandardError
attr_reader :wrapped_exception
def initialize(wrapped_exception)
super("Wrapped #{wrapped_exception.class}: #{wrapped_exception.message}")
@wrapped_exception = wrapped_exception
end
def backtrace
"#{super} #{['---WRAPPED EXCEPTION---']} #{wrapped_exception.backtrace}"
end
end
A.b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment