delayed sys.exit?

Peter Otten __peter__ at web.de
Wed Jul 29 16:40:13 EDT 2009


Dr. Phillip M. Feldman wrote:

> In the attached  http://www.nabble.com/file/p24726902/test.py test.py
> code, it appears that additional statements execute after the call to
> sys.exit(0).

>    try:
>       # If the conversion to int fails, nothing is appended to the list:
>       Runs.append(int(strs[i]))
>       if Runs[-1] <= 0:
>          print 'ERROR: ' + str(Runs[-i]) + \
>            ' is invalid; run numbers must be positive.'
>          sys.exit(0)
>    except:

sys.exit() works by raising a SystemExit exception which is caught by the 
bare except.

http://docs.python.org/library/sys.html#sys.exit
http://docs.python.org/library/exceptions.html#exceptions.SystemExit

As a general rule try to be as specific as possible when catching 
exceptions.

Peter




More information about the Python-list mailing list