I want to stop a Python script on seeing an error message. I dont want any error message on shell like exit(). How to do it ???
views:
2149answers:
1
+5
A:
When you send CTRL+C to a Python script, it raises the KeyboardInterrupt exception, so you can do something like
try:
... Work goes here ...
except KeyboardInterrupt:
sys.exit(0)
Gonzalo Quero
2009-01-27 12:35:43
+1 for deciphering the question =]
mdec
2009-01-27 12:53:57
I think he actually meant to ask how to suppress the error message/traceback at ANY error, so the 3rd line would be `except:` instead of `except KeyboardInterrupt:`
Rod Daunoravicius
2009-01-27 13:51:15
@Rod: I would certainly hope not, as that would make the program impossible to debug.
Aaron Gallagher
2009-01-27 14:14:36
@Rod: A bare except should never be used unless the error is raised again, because it hides real errors.
nosklo
2009-01-28 10:00:29