[Python-3000] New builtin exceptions classes?

"Martin v. Löwis" martin at v.loewis.de
Thu Mar 22 21:38:45 CET 2007


Frank Benkstein schrieb:
> IMHO Exceptions should carry more information about why and where the
> exception happened. A good example of an exception class carrying that
> kind of information is IOError with its 'filename' and 'errno'
> attributes (although these could be documented better). It would be
> nice if all builtin Exceptions had those kind of attributes. As an
> example KeyError could have a 'key' and a 'mapping' attribute,
> IndexError could have a 'index' and an 'sequence' attribute and so on.

This is an often-requested feature, e.g. in

http://sourceforge.net/tracker/index.php?func=detail&aid=1182143&group_id=5470&atid=355470

The primary reason that it isn't there yet is that nobody bothered to
come up with a precise specification what exception should get what
attributes. If you would like to contribute such a specification,
go ahead. An implementation would be appreciated, as well, although
that implementation certainly cannot set these attributes in all
places where the exception is raised.

This doesn't need to wait for Py3k, either: in many cases, this
can be a fully compatible change, so it can be added to 2.6 already.

Regards,
Martin



More information about the Python-3000 mailing list