[Python-ideas] Arguments to exceptions
Mark E. Haase
mehaase at gmail.com
Thu Jul 6 13:59:02 EDT 2017
On Thu, Jul 6, 2017 at 5:58 AM, Paul Moore <p.f.moore at gmail.com> wrote:
> To use the (already
>
over-used) NameError example, Ken's proposal doesn't include any
> change to how NameError exceptions are raised to store the name
> separately on the exception.
>
Maybe I'm misunderstanding you, but the proposal has a clear example of
raising NameError and getting the name attribute from the exception
instance:
try:
raise NameError(name=name, template="name '{name}' is not defined.")
except NameError as e:
name = e.kwargs['name']
msg = str(e)
...
Yes. Because he tries to extract the name component of a NameError,
>
and yet that component isn't stored anywhere - under his proposal or
> under current CPython.
>
I'm not sure what you mean by "extract", but the proposal calls for the
name to be passed as a keyword argument (see above) and stored in
self.kwargs:
class BaseException:
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
I think this code does what you're asking it to do, right?
(N.B. BaseException is written in C, so this Python code is presumably
illustrative, not an actual implementation.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170706/743b1c24/attachment-0001.html>
More information about the Python-ideas
mailing list