]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Improved error handling.
authorGuido van Rossum <guido@python.org>
Wed, 18 Dec 1991 13:38:42 +0000 (13:38 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 18 Dec 1991 13:38:42 +0000 (13:38 +0000)
Demo/scripts/from.py

index 20771a07d8e23ab369527b6706f7c55b781d37f1..21ca081669ef92f56e7b5cf3cad58ec4af98f6f0 100755 (executable)
@@ -4,11 +4,22 @@
 # Extension to multiple mailboxes and other bells & whistles are left
 # as exercises for the reader.
 
-import posix
+import sys, posix
 
 # Open mailbox file.  Exits with exception when this fails.
 
-mail = open(posix.environ['MAIL'], 'r')
+try:
+       mailbox = posix.environ['MAIL']
+except RuntimeError:
+       sys.stderr.write \
+               ('Please set environment variable MAIL to your mailbox\n')
+       sys.exit(2)
+
+try:
+       mail = open(mailbox, 'r')
+except RuntimeError:
+       sys.stderr.write('Cannot open mailbox file: ' + mailbox + '\n')
+       sys.exit(2)
 
 while 1:
        line = mail.readline()