osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

revisiting the "What am I running on?" question


On Wed, Feb 20, 2019 at 6:29 AM Terry Reedy <tjreedy at udel.edu> wrote:
>
> On 2/19/2019 10:06 AM, Chris Angelico wrote:
> > On Wed, Feb 20, 2019 at 2:04 AM Chris Angelico <rosuav at gmail.com> wrote:
> >>
> >> On Wed, Feb 20, 2019 at 1:59 AM songbird <songbird at anthive.com> wrote:
> >>>
> >>> MRAB wrote:
> >>> ...
> >>>> Don't use a bare except, it'll catch _any_ exception.
> >>>
> >>>    that's ok with this code IMO, but i see your point.
> >>>
> >>
> >> Not really, no. It means that ANY bug (barring an outright syntax
> >> error) inside the try block will silently move you on to the next
> >> check, possibly after printing out the message.
> >
> > 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.
>
> KeyboardInterrupt, SystemExit, and GeneratorExit are BaseExceptions but
> not Exceptions
>

Yes, and "except:" will catch them. Of them, KeyboardInterrupt is the
easiest example, as it can be caused by something outside the Python
program's control, has specific user-facing meaning, and can happen
literally anywhere (IIRC it's "between any two Python bytecodes", in
CPython). Suppressing KeyboardInterrupt can be done explicitly, but
should not be done accidentally.

ChrisA