Last active
February 8, 2018 05:54
-
-
Save vemarav/cc93c9d2dc1580fafb73b8808ccf0628 to your computer and use it in GitHub Desktop.
Defining Custom Errors for ruby library(ruby-gem)
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
# 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