Simple exceptions question

Brett Kelly inkedmn at gmail.com
Mon Aug 16 15:41:17 EDT 2004


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

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

etc.

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