INPUT_FILENAME = "input.txt" #Author: James Tam #Version: November 1, 2024 #Learning objective: #*Recovering from a file IO run time error using exceptions #*Note: # -The example is as simple as possible which is why it doesn't handle # things as well as it should e.g. it just tells the user about the error # but doesn't do anything else. # -But it won't crash if problems occur during the opening, reading or # even the closing of the file. #Trying to open or read from a file may result in an exception being raised. try: aFile = open("input.txt","r") print(aFile.readline()) aFile.close() except IOError: print("Problem encounted during the interaction with %s" %(INPUT_FILENAME))