Skip to content

Instantly share code, notes, and snippets.

@casperisfine
Created December 13, 2023 10:19
Show Gist options
  • Save casperisfine/5446da2a4e0840d6f5ca4d8e214b68e1 to your computer and use it in GitHub Desktop.
Save casperisfine/5446da2a4e0840d6f5ca4d8e214b68e1 to your computer and use it in GitHub Desktop.
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