Interest check in some delicious syntactic sugar for "except:pass"
andreengels at gmail.com
Wed Mar 3 12:02:32 CET 2010
On Wed, Mar 3, 2010 at 10:27 AM, Oren Elrad <orenelrad at gmail.com> wrote:
> Howdy all, longtime appreciative user, first time mailer-inner.
> I'm wondering if there is any support (tepid better than none) for the
> following syntactic sugar:
> ........ block
> The logic here is that there are a ton of "except: pass" statements
> floating around in code that do not need to be there. Meanwhile, the
> potential keyword 'silence' does not appear to be in significant use
> as a variable, or an alternative keyword might be imagined
> ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of
> 'silence' since that is precisely what it does to the block (that is,
> you have to inflect it as a verb, not a noun -- you are telling the
> block to be silent). Finally, since this is the purest form of
> syntactic sugar, I cannot fathom any parsing, interpreting or other
> complications that would arise.
> I appreciate any feedback, including frank statements that you'd
> rather not trifle with such nonsense.
I would be against this, because "except: pass" is a terrible code
smell. Usage of exceptions can roughly be divided into two areas:
1. Cases where you do know quite well what might go wrong
2. Cases where all kind of stuff might go wrong, including things you
perhaps did not think of, and want to deal with all of them
In the first case, you should not use a blanket "except", but a more
specific one, catching only the specific error or errors you are
In the second case, a blanket except might well be correct, but in
that case, you should not want to pass over the error silently.
Usually you will want to notify the user that an error has occurred.
Even if that is not the case, you want to make some kind of logging of
the error, so that you have the chance of finding it if it is indeed
an unexpected (and therefore undoubtedly also unintended) error.
Doing a pass over an exception is not a bad thing in itself, but one
should only do it when one _knows_ that it is the right action to
take. If you have a general exception, you don't know _what_ has gone
wrong, so you sure as hell cannot be sure about what's the best action
to take. Doing nothing might well be your best guess, but even in that
case I want to know that your program has been guessing when I use it.
André Engels, andreengels at gmail.com
More information about the Python-list