Skip to content

Instantly share code, notes, and snippets.

@ParadoxV5
Created May 25, 2024 03:14
Show Gist options
  • Save ParadoxV5/a7daf271a32104a68c6fc49264b3a8a9 to your computer and use it in GitHub Desktop.
Save ParadoxV5/a7daf271a32104a68c6fc49264b3a8a9 to your computer and use it in GitHub Desktop.
# Marker module for “my library”
module MyError end
# Built-in exception class example
ZeroDivisionError.include MyError
puts begin
1 / 0
rescue MyError => e
e
end #=> divided by 0
# Custom exception class example
class APIError < RuntimeError
include MyError
end
puts begin
raise APIError, 'oof'
rescue MyError => e
e
end #=> oof
# Non-match example
puts begin
0 + ''
rescue MyError => e
e
end #!> path/to/module-scoped rescue.rb:24:in `+': String can't be coerced into Integer (TypeError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment