File: class/Workbook/Exercises/Lab7/ex2.txt

% cat oops.py
MyError = 'hello'

def oops():
    raise MyError, 'world'

def doomed():
    try:
        oops()
    except IndexError:
        print 'caught an index error!'
    except MyError, data:
        print 'caught error:', MyError, data
    else:
        print 'no error caught...'

if __name__ == '__main__':
    doomed()

% python oops.py
caught error: hello world



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