except clause not catching IndexError

Derek Schuff dschuff at purdue.edu
Wed Feb 22 12:39:42 EST 2006


Erwin S. Andreasen wrote:

> Did you by any chance do something like:
> 
> except ValueError, IndexError:
> 
> at some point earlier in this function? That, when catching ValueError
> assigns the resulting exception to IndexError (and so the following
> except IndexError: wouldn't work as IndexError is no longer what you
> think it is). The correct syntax for catching multiple exceptions is:
> 
> except (ValueError, IndexError), targetVariable:
> 
> You could verify this by doing a print repr(IndexError) before your
> line 202, to see that it really is the IndexError builtin.
> 

hey, nice catch. In fact I did exactly that. in my search for a solution for
this problem i discovered the catch-a-tuple-of-exceptions error, and in
fact fixed it, but didn't realize that it was related to the one I posted.
(the idea that exceptions can be redefined caught me off guard).

thanks (to both of you who responded),
-derek



More information about the Python-list mailing list