File: class/Extras/Other/PriorClasses/lmco-nov12/excs2.py

# 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.py'. 42)

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

import lib

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










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