More informative error messages (Re: [Python-Dev] Efficient predicates for the standard library)

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Oct 7 23:06:15 EDT 2003


"Fred L. Drake, Jr." <fdrake at acm.org>:

> this cost was once attributed with a fairly bad performance
> degradation when we tried a nicer message for AttributeError that
> caused the exception instance to always be created

This suggests that perhaps using exceptions for non-exceptional flow
control isn't such a good idea, if it forces things like
AttributeError to be less useful for debugging than they would
otherwise be.

I know the Python philosophy holds that you *should* be able to use
exceptions freely for both purposes, but perhaps that philosophy needs
to be re-examined in the light of this consideration.

I know I find myself preferring these days to use getattr et al with
default arguments rather than catching exceptions when testing for the
presence of something, as it seems to more directly express what I'm
trying to do, and avoids all chance of catching the wrong
exception. Perhaps the equivalent should be done inside the
interpreter, too?

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+



More information about the Python-Dev mailing list