Created
December 13, 2023 10:19
-
-
Save casperisfine/5446da2a4e0840d6f5ca4d8e214b68e1 to your computer and use it in GitHub Desktop.
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 UnserializableError < StandardError | |
def initialize(...) | |
super | |
@oops = -> () { } | |
end | |
end | |
NormalError = Class.new(StandardError) | |
error = begin | |
begin | |
raise UnserializableError, "Won't serialize" | |
rescue UnserializableError | |
raise NormalError, "Normal" | |
end | |
rescue NormalError => e | |
e | |
end | |
p error | |
begin | |
Marshal.dump(error) | |
rescue TypeError => e | |
puts "#{e.class}: #{e.message}" | |
end | |
def clear_cause(error, new_cause) | |
begin | |
raise error, cause: new_cause | |
rescue error.class => new_error | |
return new_error | |
end | |
end | |
new_error = clear_cause(error, nil) | |
p new_error.cause | |
new_error = clear_cause(error, StandardError.new) | |
p new_error.cause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment