[issue18162] Add index attribute to IndexError

Brett Cannon report at bugs.python.org
Sun Jun 16 06:29:05 CEST 2013


Brett Cannon added the comment:

Obviously it can't be required that the index be provided as that would break way too much code. There are already exceptions in the stdlib that have optional attributes you can choose to (not) set.

As for relying upon it, it would be just like any other object that gets a new attribute: either you rely on it because you know the code you are using always provides it (e.g. using core/stdlib code directly) or you use some way to deal with cases where it was not set (EAFP or LBYL). Subclassing IndexError to provide a inheritance guarantee that an attribute exists seems like overkill (e.g. IndexError2 so you can do ``except IndexError2 as exc:``).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18162>
_______________________________________


More information about the Python-bugs-list mailing list