Simple exceptions question

Nick Jacobson nicksjacobson at yahoo.com
Mon Aug 16 15:06:52 EDT 2004


Say I have a function foo that throws an IndexError exception, and I
want to handle it:

def foo(a, b, c):
    print a[10], b[10], c[10] #, etc.

def main():
    #define vars
    try:
        foo(a, b, c)
    except IndexError:
        print "Accessed array ", x, " out of bounds!" #???

When the exception is thrown, I don't know what triggered it!  a, b,
or c?

I could put a series of if statements in the except clause, but that
defeats the whole purpose of having the exception, right?  Is there a
better way?

Thanks in advance!

--Nick



More information about the Python-list mailing list