[Tutor] IOError exception handling

alan.gauld@bt.com alan.gauld@bt.com
Mon, 29 Jul 2002 11:19:06 +0100


> Many thanks.  Betwixt the two of you, I've now got:
> 
> def errortest():
>     try: ...
>     except IOError, e:
>         if e[0] == 2: return 0  # file not found
>         print e                 # any other error
>         sys.exit(1)

A minor point. Inside a function rather than use sys.exit() 
I prefer to "raise SystemExit"

This has the same effect but avoids the need to import sys.

Just a thought. 
(And no my tutor doesn't (yet) mention this, I only discovered 
the advantages of SystemExit after I wrote the tutor! :-)

Alan G.