mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Improved error handling.
This commit is contained in:
		
							parent
							
								
									5378d5c485
								
							
						
					
					
						commit
						5558b89320
					
				
					 1 changed files with 13 additions and 2 deletions
				
			
		|  | @ -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() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum