Last active
August 29, 2015 14:05
-
-
Save jorge-lavin/12874985bb23b18d1e6f 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
# Code taken from http://codereview.stackexchange.com/a/61539/52090 | |
import sys | |
exit_codes = [ | |
(ValueError, 10), | |
(KeyError, 25) | |
] | |
# now you can also use a dictionary here, but | |
# the ordering is not defined, so if you have a | |
# superclass and subclass, then your code will sometimes | |
# if the superclass is matched before subclass! | |
try: | |
raise Some_Exception | |
except tuple(e[0] for e in exit_codes) as exit_err: | |
for exc_class, code in exit_codes: | |
if isinstance(exit_err, exc_class): | |
sys.exit(code) | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment