Describe how catching exceptions can help with file errors. Write three Python examples that actually generate file errors on your computer and catch the errors with try: except: blocks. Include the code and output for each example in your post.
Describe how you might deal with each error if you were writing a large production program. These descriptions should be general ideas in English, not actual Python code.
#1
#Code:
try:
a = 1/0
print(a)
except ZeroDivisionError:
print("Zero!")
#2
#Code:
try:
a = []
print(a[1])
except IndexError:
print("Index error")
#3
#Code:
try:
A = 42
A = A + ' 4 '
except TypeError:
print('Wrong type')
Comments
Leave a comment