Skip to content

Instantly share code, notes, and snippets.

@rcoh
Last active December 15, 2015 05:19
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 rcoh/5207772 to your computer and use it in GitHub Desktop.
Save rcoh/5207772 to your computer and use it in GitHub Desktop.
How to Hang Yourself With Exceptions
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):
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