[Tutor] IOError exception handling
Sean 'Shaleh' Perry
shalehperry@attbi.com
Mon, 29 Jul 2002 02:34:10 -0700 (PDT)
>
> Which works when I force errors of several types. Do I need the
> sys.exit(1), and is 1 a reasonable generic number? I've seen it in
> several examples, and since I'm still partly in monkey-see, monkey-do
> mode, I stuck it in even though it superficially works without it. :-)
without the sys.exit you would not exit (-: if you "need" it is another matter
and up to you.
As to the parameter for sys.exit(), 0 is success and non 0 is failure. I often
use -1 for input issues and 1 for faults.
i.e.
if len(sys.argv) != 2:
print 'Usage: app input'
sys.exit(-1)
if not file_exists:
sys.exit(1)