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

Fred L. Drake, Jr. fdrake at
Tue Oct 7 22:20:04 EDT 2003

Ian Bicking writes:
 > Personally, I usually add the repr of any interesting arguments to my 
 > exceptions.  But many of Python's exceptions don't do this.  Is there a 
 > reasoning there?  Sometimes the repr of an object can be verbose, or in 
 > getting it you can cause a second error.  Is this the reason for the 
 > lack of information, or is it just an oversight?  Or a differing 
 > opinion on how one should debug things?

Another reason is efficiency.  Some exceptions are raised and caught
within the C code of the interpreter.  For these cases, it is
important that the raise be as efficient as possible, so the
interpreter attempts to avoid instantiation of the exception instance;
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 (fixed before
release, of course, IIRC!).

That's not to say that there aren't several places where better
exception messages can't be used effectively.  This is only an issue
for exceptions that are going to be frequently raised and caught in C


Fred L. Drake, Jr.  <fdrake at>
PythonLabs at Zope Corporation

More information about the Python-Dev mailing list