Last active
December 15, 2015 05:19
-
-
Save rcoh/5207772 to your computer and use it in GitHub Desktop.
How to Hang Yourself With Exceptions
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
import other | |
def thrower(): | |
raise other.Exp1 | |
def catcher(): | |
try: | |
thrower() | |
except other.Exp1, other.Exp2: | |
pass | |
catcher() | |
x = other.Exp2("some message") | |
# Outputs: | |
# TypeError: 'Exp1' object is not callable | |
# ???????? | |
# except other.Exp1, other.Exp2 is equivalent to | |
# except other.Exp2 as other.Exp2, creating an alias. | |
# Enjoy strange errors throughout your code :-) | |
# Correct: | |
# except (other.Exp1, other.Exp2): |
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
class Exp1(Exception): | |
pass | |
class Exp2(Exception): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment