Enhanced information from common exceptions

Paul Rubin phr-n2002a at nightsong.com
Sat Mar 16 21:34:17 EST 2002


Tim Peters <tim.one at comcast.net> writes:
> A difficulty with this kind of thing is that producing exception info
> doesn't come for free.  Before 2.2, raising IndexError was the only way to
> terminate a "for" loop via normal exhaustion, and the list indexing code has
> no idea *why* it's being called.  If it produced more info on an
> out-of-range index, it would slow down every normal loop by the time it took
> to construct a nice exception message doomed to be thrown away unlooked-at.
> Note that the integers in your ideal message have to go through binary ->
> decimal string conversion, and lots of dynamic string fiddling to paste all
> the msg pieces together.  The cycles add up fast.

Well, raising the exception could put the index and list length into
slots in the exception object, rather than formatting them.  Exception
objects could even have a few built-in slots for such purposes, so
they wouldn't have to contain dictionaries.



More information about the Python-list mailing list