File: class/Workbook/Examples/Lecture8/classexc.py

class Super:      pass
class Sub(Super): pass

def raiser1():
    X = Super()           # raise listed class instance
    raise X

def raiser2():
    X = Sub()             # raise instance of subclass
    raise X

for func in (raiser1, raiser2):
    try:
        func()
    except Super:                # match Super or a subclass
        import sys
        print 'caught:', sys.exc_info()[0]



[Home page] Books Code Blog Python Author Train Find ©M.Lutz