revisiting the "What am I running on?" question
On Wed, Feb 20, 2019 at 3:26 AM Grant Edwards <grant.b.edwards at gmail.com> wrote:
> On 2019-02-19, Chris Angelico <rosuav at gmail.com> wrote:
> > Oh, and not just bugs either. If the user hits Ctrl-C at just the
> > right moment, KeyboardInterrupt will be raised. You'll swallow that
> > exception silently, preventing the user-requested halt, and going and
> > doing the wrong thing. Don't use a bare except clause even if your
> > code is 100% perfect every time. (And anyone who thinks their code is
> > perfect hasn't tested it.)
> IMO, you're allowed to use a bare except clause to do cleanup or
> logging as long as the execption handler ends with the line
Yeah, I was clearer about that in the first email, to which that was a
followup, but I'll give two examples of valid bare-except constructs:
show failure state
thing = get_next_thing()
except NoMoreThings, KeyboardInterrupt:
response = some_handler(thing)
response = 500
The implication of the second one is that (a) bugs in some_handler()
shouldn't break the whole program, and (b) attempting to halt
some_handler() with Ctrl-C shouldn't halt the whole program. It
creates a boundary.
But you should ALWAYS either reraise or log the exception. ALWAYS.
Otherwise, be specific about what you're swallowing.