[Python-Dev] Pre-PEP: Exception Reorganization for Python 3.0
Stephen J. Turnbull
stephen at xemacs.org
Mon Aug 1 15:52:06 CEST 2005
>>>>> "Willem" == Willem Broekema <metawilm at gmail.com> writes:
Willem> I hope the above makes the way I'm thinking more clear.
Willem> Like Phillip J. Eby, I think that labeling
Willem> KeyboardInterrupt a CriticalException seems wrong; it is
Willem> not an error and not critical.
Uh, according to your example in Common LISP it is indeed an error,
and if an unhandled signal whose intended interpretation is "drop the
gun and put your hands on your head!" isn't critical, what is?<wink>
I didn't miss your point, but I don't see a good reason to oppose that
label based on the usual definitions of the words or Common LISP
It seems to me the relevant question is "is it likely that catching
KeyboardInterrupt with 'except Exception:' will get sane behavior from
a generic user-defined handler?" I think not; usually you'd like
generic error recovery to _not_ bother the user, but KeyboardInterrupt
sort of demands interaction with the user, no? So you're going to
need a separate routine for KeyboardInterrupt, anyway. I expect
that's going to be the normal case.
So I would say KeyboardInterrupt should derive from CriticalException,
not from Exception.
I definitely agree that implementing recovery features is a good idea,
and in interactive operation (or with an option to the interpreter),
to allow for such recovery in the interpreter itself. For example,
the interpreter could keep a small nest egg of memory for the purpose
of interacting with the user; this would be harder for a program to
do. And in many quickie scripts it would be convenient if the
interpreter would drop into interactive mode, not die, if the program
encounters a critical exception.
But it's still a critical exception to the program written in Python,
even if it's easy for the user to handle and the interpreter provides
the capability to pass the buck to the user. The program has
completely lost control!
School of Systems and Information Engineering http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
More information about the Python-Dev