On Tue, Oct 13, 2020 at 9:55 AM David Mertz <[email protected]> wrote:

> If you really want a snazzy highly-parameterized exception, write it
> yourself as a class factory.  I won't particularly like the antipattern,
> but it's available now.
>
> if some_bad_thing:
>     raise ExceptionMaker("BadStuffErrror", details, plus, more_details)
>
> Implementation of 'ExceptionMaker' left to readers.  But it's possible to
> write once.
>

 I was thinking the same thing, and you could even write a fancy
__getattrr__, so you could do:

raise ExceptionMaker.BadStuffErrror(details, plus, more_details)

 But here's where I am still completely confused. In order to catch that
Exception, you need know about it -- it's name, what parameters it uses,
etc.

And that will be potentially very far from the code that creates it.

And what if you want to raise the same (or similar)  exception somewhere
else?

The OP has stated that all making an Exception class does is create a name
-- which is true (though the other thing it does is put that name in a
class hierarchy) -- but the thing is -- that's very useful! In fact, I
can't see how you could do this at all without creating a name somewhere
that it could be accessed from elsewhere.

-CHB






> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/M7LP4OMSEU47MBWX75KGBM7343SH5XGI/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/DJDE6YDRY3WK7VAL6ID5JXCZYSNGIVAA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to