File: class/Extras/Other/PriorClasses/scotts-sep12/except-objects.txt

# lib.py

class Bads(Exception):
    def __init__(self, file, line):
        self.file = file
        self.line = line

class Bad1(Bads): pass
class Bad2(Bads): pass
class Bad3(Bads): pass

def func1():
    ...
    raise Bad1('spam.txt', 99)

def func2():
    ...
    raise Bad2('eggs.txt', 88)

##################################
# client.py

import lib
try:
    lib.func1()
except Exception:
    ...
except Bads as X:
    print X.file, X.line
...





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