Help: except clause ordering

Bob bbondi at pacbell.net
Sat Mar 1 18:52:43 EST 2003


C:\Python22\Doc\tut\node11.html#SECTION0011100000000000000000 is the
location on my PC with the 9.7.1 Exceptions Can Be Classes section
displayed you can see this example which will display
B
C
D

class B:
    pass
class C(B):
    pass
class D(C):
    pass

for c in [B, C, D]:
    try:
        raise c()
    except D:
        print "D"
    except C:
        print "C"
    except B:
        print "B"

yet if moving the except clauses to reverse the order what is
displayed is
B
B
B
this is all just as the tutorial says. I do not 'get it'. Why B, B, B
rather than D, C, B?




More information about the Python-list mailing list