Simple exceptions question
nicksjacobson at yahoo.com
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
> e.name = self.name
> raise e
> Thus you can write the except clause as:
> except IndexError, e:
> print "Accessed array ", e.name, " out of bounds at", e.index
It says that "self.name" is undefined:
"AttributeError: 'seq' object has no attribute 'name'"
More information about the Python-list