# This example shows exceptions import sys import string import exceptions # Create a new exception class LowerCaseException(exceptions.Exception): def __init__(self, args=None): self.args = args # Input a character and perhaps raise an exception def doInput(): c = sys.stdin.read(1) if c == "": raise EOFError, 'End of file occurred' if c in string.lowercase: raise LowerCaseException, c return c # Execution begins here print "Enter some characters: " while 1: try: char = doInput() except LowerCaseException, e: char = e[0] char = string.upper(char) except EOFError, e: print e sys.exit('Bye') except Exception, e: # Exception catches anything print e sys.exit('Something happened') if char == 'q': break print char, print "You entered quit"