[Python-Dev] Proposing a sys.special_exceptions tuple

Nick Coghlan ncoghlan at email.com
Fri Oct 1 08:51:07 CEST 2004


Quoting Raymond Hettinger <python at rcn.com>:
> Since we're trying to catch anything *not* special, is the intended
> usage something like this:
> 
>     try:
>         func()
>     except special_exceptions:
>         raise
>     except:
>         altfunc()  # handle non-special exceptions

Yep. It's essentially a workaround for the fact that we can't do anything too
drastic to the exception heirarchy without serious backwards compatibility
problems, but have some 'critical' exceptions that most code shouldn't be
suppressing.

At the moment, 'except:' is bad, and in most cases 'except Exception:' isn't any
better (which surprised me - I didn't realise this until Tim brought it up
recently). Tim suggested 'except StandardError:' which is an improvement but
still not quite right (SystemExit and StopIteration make it through then, but
MemoryError and KeyboardInterrupt still get eaten).

I'm dreaming of the day when I can hit 'Ctrl-C' on any Python script and
actually have the darn thing stop without hitting it 10 more times ;)

Cheers,
Nick.

-- 
Nick Coghlan
Brisbane, Australia


More information about the Python-Dev mailing list