Re: SystemExit

Guido.van.Rossum@cwi.nl
Mon, 10 May 1993 17:49:24 +0200

On the contrary, SystemExit is a big improvement. Now you can do
things like

"put the tty in raw mode"
try:
"some code that may call sys.exit(n) somewhere deep inside"
finally:
"put the tty in cooked mode again"

without having to worry about the possibility that you never hit the
finally clause. It is still possible but less likely during normal
code. Nobody in their right mind would use posix._exit(n) except to
exit from a forked child, but lots of code may call sys.exit(n) -- as
you have experienced, otherwise you wouldn't have started this thread
in the first place :-)

Code that uses an unqualified except clause is always suspect. It may
mask exceptions caused deep inside that you didn't know were possible,
such as SystemError, MemoryError or TypeError in code that you thought
had no bugs.

A solution to your problem that is more elegant than testing the value
of sys.exc_type (which is really meant for the debugger only), and
which generalizes slightly better as well, is the following:

try:
"some code that may raise any exception"
except SystemExit, status:
raise SystemExit, status
except:
"handle any other kind of error"

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>

PS: I'll reply to your previous mail later since the issues are more
complicated...