Created
March 15, 2013 22:52
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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