>>> class B: pass ... >>> class C(B): pass # C isa B ... >>> class D(C): pass # D isa C ... >>> for klass in (B, C, D): ... try: ... instance = klass() ... raise instance ... except D: # order matters: ... print 'D' # most specific first, ... except C: # else prints B, B, B ... print 'C' ... except B: ... print 'B'