[Python-ideas] Improving Catching Exceptions
Sven R. Kunze
srkunze at mail.de
Wed Jun 28 07:48:16 EDT 2017
On 28.06.2017 08:00, Nick Coghlan wrote:
> Right, and I'd like us to keep in mind the KeyError -> AttributeError
> (and vice-versa) use case as well. Similar to ExitStack, it would be
> appropriate to make some additions to the "recipes" section in the
> docs that covered things like "Keep AttributeError from being
> suppressed in a property implementation".
As it was snipped away, let me ask again:
I don't see how this helps differentiating shallow and nested exceptions
such as:
try:
with exception_guard(ImportError):
import myspeciallib
except RuntimeError: # catches shallow and nested ones
import fallbacks.MySpecialLib as myspeciallib
At least in my tests, exception_guard works this way and I don't see any
improvements to current behavior. Moreover, I am somewhat skeptical that
using this recipe will really improve the situation. It's a lot of code
where users don't have any stdlib support. I furthermore doubt that all
Python coders will now wrap their properties using the guard. So, using
these properties we will have almost no improvement. I still don't see
it as the responsibility of coder of the property to guard against
anything. Nobody is forced to catch exceptions when using a property.
If that's the "best" outcome, I will stick to
https://stackoverflow.com/questions/20459166/how-to-catch-an-importerror-non-recursively
because 1) Google finds it for me and 2) we don't have to maintain 100
lines of code ourself.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170628/8831006c/attachment.html>
More information about the Python-ideas
mailing list