[Patches] indexerror: better error messages

Greg Stein gstein@lyra.org
Sun, 11 Jun 2000 13:38:44 -0700


On Sun, Jun 11, 2000 at 10:04:42PM +0200, M.-A. Lemburg wrote:
> > 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.

Agreed: at raise time, it should be *fast*. However, at *print* time, it can
take a little longer.

If Peter can make the raise fast, and defer the formatting time to the
print, then this patch would be reasonable.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/