summaryrefslogtreecommitdiffstats
path: root/Demo/scripts
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-12-18 13:38:42 (GMT)
committerGuido van Rossum <guido@python.org>1991-12-18 13:38:42 (GMT)
commit5558b89320744797ff6c97c70c2308d805e7ee3d (patch)
tree8ccc7efc4b6a7589a935752e36ddcda592af4792 /Demo/scripts
parent5378d5c485f8204630ac0e7db3276d3a852b4317 (diff)
downloadcpython-5558b89320744797ff6c97c70c2308d805e7ee3d.zip
cpython-5558b89320744797ff6c97c70c2308d805e7ee3d.tar.gz
cpython-5558b89320744797ff6c97c70c2308d805e7ee3d.tar.bz2
Improved error handling.
Diffstat (limited to 'Demo/scripts')
-rwxr-xr-xDemo/scripts/from.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Demo/scripts/from.py b/Demo/scripts/from.py
index 20771a0..21ca081 100755
--- a/Demo/scripts/from.py
+++ b/Demo/scripts/from.py
@@ -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()