[Python-ideas] Let try-except check the exception instance

Nick Coghlan ncoghlan at gmail.com
Thu May 31 10:36:43 EDT 2018

On 31 May 2018 at 14:47, Danilo J. S. Bellini <danilo.bellini at gmail.com>

> The idea is to allow catching exceptions beyond checking their MRO,
> using a class that checks the exception instance by implementing
> a custom __instancecheck__.

The exception machinery deliberately attempts to avoid instantiating
exception objects whenever it can, but that gets significantly more
difficult if we always need to create the instance before we can decide
whether or not the raised exception matches the given exception handler

So quite aside from any philosophy-of-design questions, we're unlikely to
ever implement this simply for laziness-of-evaluation reasons. (There are
already lots of circumstances that force instantiation - that doesn't mean
we're keen to add more)


P.S. There's a somewhat related issue aimed at getting ABCs to work
correctly as exception handlers, although that still sticks to the
principle that exception handler checks solely consider the exception type,
not its value: https://bugs.python.org/issue12029

Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180601/1522b698/attachment-0001.html>

More information about the Python-ideas mailing list