File: LP6E/Chapter35/categoric2.py

class General(Exception): pass
class Specific1(General): pass
class Specific2(General): pass

def raiser0(): raise General()
def raiser1(): raise Specific1()
def raiser2(): raise Specific2()

for func in (raiser0, raiser1, raiser2):
    try:
        func()
    except General as X:                 # X is the raised instance
        print('caught:', type(X))        # Same as sys.exc_info()[0], X.__class__



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