Skip to content

Instantly share code, notes, and snippets.

@vemarav
Last active February 8, 2018 05:54
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 vemarav/cc93c9d2dc1580fafb73b8808ccf0628 to your computer and use it in GitHub Desktop.
Save vemarav/cc93c9d2dc1580fafb73b8808ccf0628 to your computer and use it in GitHub Desktop.
Defining Custom Errors for ruby library(ruby-gem)
# let say you have a class Game and its Audio
module Audio
class NoDeviceError < Error::ENODEV # (No such device)
end
end
class Game
include Audio
class Error < StandardError
end
class GraphicError < Error
end
end
# To handle Game::GraphicError and Audio::NoDeviceError
# the library user can rescue Game::Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment