Created
November 22, 2023 23:23
-
-
Save pjambet/2863eff20180ae1bf513c0ae1b1252e6 to your computer and use it in GitHub Desktop.
Explicitly set a cause
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
def foo(exception) | |
raise StandardError, "I'm an error thrown by the method caused by #{exception.class}", cause: exception | |
end | |
def always_raise(message) | |
raise message | |
end | |
def rescue_exception | |
yield | |
rescue StandardError => e | |
e | |
end | |
error = rescue_exception { always_raise("I'm the original error") } | |
foo(error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment