Simple exceptions question

Brett Kelly inkedmn at
Mon Aug 16 21:41:17 CEST 2004

You could use multiple print statements in your function (and still
achieve the same output)

print a[10],
print b[10],
print c[10]


kinda hackish, i know

Nick Jacobson wrote:
> 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