File: class/Extras/Other/PriorClasses/schwab-sep12/excepts.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', 42)

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

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



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