# lib.py class MathErr(Exception): pass class DivZero(MathErr): pass class Uflow(MathErr): pass class Oflow(MathErr): pass def f1(): .... raise DivZero(.......) ... raise Uflow() ------------ # client.py import lib try: lib.f1() except lib.MathErr as E: E.method() if isinstance(E, lib.Uflow): ... sys.exit(N)