[Patches] indexerror: better error messages

M.-A. Lemburg mal@lemburg.com
Sun, 11 Jun 2000 22:04:42 +0200


> error messages like "list index out of range" are not very
> helpful. a discussion about better error messages on the
> python mailing list proposed to add information about the
> value of the index which caused the IndexError and about
> the valid range.a few examples:
> 
> "abc"[3]
> IndexError: string index 3 out of range [0..2]
> 
> u"guido"[-10]
> IndexError: unicode string index -10 out of range [-5..-1]
> 
> [][7]
> IndexError: cannot get item from empty list
> 
> The speed penalty in case of a caught exception is constant
> and imho negligibly.

I'm -2 on this one: errors which are raised *very* often
like IndexError and AttributeError should not do any
performance relevant actions during the raise operation.

Finding out the cause of an error is easy enough by
simply looking at the traceback when the error is being
printed.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/