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.
Comment your code to demonstrate that you know what you are talking about!
"""Creates an exception object. The program stops running at this point and python prints out the traceback, which ends with a message describing the exception that occured."""
try:
a=1/0
print(a)
except ZeroDivisionError:
print("Zero error!")
try:
a=[]
print(a[1])
except IndexError:
print("IndexErro")
try:
a=42
a=a+'9'
except TypeError:
print("Wrong type")
"""Another large opportunity to deal with this error is development and dessgn process"""
These are output for each example.
Comments
Leave a comment