Simple exceptions question

Nick Jacobson nicksjacobson at
Tue Aug 17 13:02:02 CEST 2004

Thanks for the reply!  I'm definitely trying this out..

> the python interpreter. Its easy to find out, which statement caused
> the exception.

How can you do that?

> Yes: create your own list class (maybe by inheriting list). Give each
> instance an unique name. Use a setitem method like this: 
> class seq(list):
>   # some code suppressed...
>   def   getitem  (self,index):
>     try: list.  getitem  (self,index)
>     except IndexError,e:
>       e.index = index
> =
>       raise e
> Thus you can write the except clause as:
>   except IndexError, e:
>     print "Accessed array ",, " out of bounds at", e.index 
> Mathias

It says that "" is undefined:
"AttributeError: 'seq' object has no attribute 'name'"

More information about the Python-list mailing list