Skip to content

Instantly share code, notes, and snippets.

@avalanchy
Created September 16, 2013 12:20
Show Gist options
  • Save avalanchy/6580007 to your computer and use it in GitHub Desktop.
Save avalanchy/6580007 to your computer and use it in GitHub Desktop.
python exception inheritance
class A(Exception):
pass
class B(A):
pass
try:
raise B
except A:
print 'raised B, excepted A'
try:
raise A
except B:
print 'raised A, catched B'
# output
raised B, excepted A
Traceback (most recent call last):
File "exceptions.py", line 15, in <module>
raise A
__main__.A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment