Skip to content

Instantly share code, notes, and snippets.

@pjambet
Created November 22, 2023 23:23
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 pjambet/2863eff20180ae1bf513c0ae1b1252e6 to your computer and use it in GitHub Desktop.
Save pjambet/2863eff20180ae1bf513c0ae1b1252e6 to your computer and use it in GitHub Desktop.
Explicitly set a cause
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