[Python-ideas] Arguments to exceptions
rosuav at gmail.com
Sat Jul 15 20:33:15 EDT 2017
On Sun, Jul 16, 2017 at 10:12 AM, Jeff Walker <jeff.walker00 at yandex.com> wrote:
> The first problem is that there is no direct access to the components that make up the error in some of the standard Python exceptions.
> >>> foo
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name 'foo' is not defined
> If you need access to the name, you must de-construct the error message. To get direct access to the name, it would need to be passed to the exception when raised. Why wasn't that done?
Because it normally isn't needed. Can you give an example of where
NameError could legitimately be raised from multiple causes? Most of
the time, NameError is either being used to probe a feature (eg
raw_input vs input), or indicates a bug (in which case you just let
the exception get printed out as is). When do you actually need access
to that name?
More information about the Python-ideas