delayed sys.exit?

  • Thread starter Dr. Phillip M. Feldman
  • Start date
D

Dr. Phillip M. Feldman

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).
I'll be grateful if anyone can shed light on why this is happening. Below
is a copy of some sample I/O. Note that in the last case I get additional
output after what should be the final error message.

In [126]: run test
Input a string: 1,2
[1, 2]

In [127]: run test
Input a string: 1-3
[1, 2, 3]

In [128]: run test
Input a string: 1,4,5-12
[1, 4, 5, 6, 7, 8, 9, 10, 11, 12]

In [129]: run test
Input a string: 0
ERROR: 0 is invalid; run numbers must be positive.
ERROR: '0' is not a valid run number.
 
P

Peter Otten

Dr. Phillip M. Feldman said:
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))
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top