In Python, you can handle errors with exceptions. The following code will generate an FileNotFound error because the file it is trying to open does not exist:
fh = open('data.txt') for strline in fh.readlines(): print(strline)
FileNotFoundError: [Errno 2] No such file or directory: 'data.txt'
An error is generated and the program stop executing. Suppose, we want to program to continue because we will compensate for this error later in the code. We can use try: except: