Answer to Question #257120 in Python for Phikem

Question #257120

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!



1
Expert's answer
2021-10-28T01:28:33-0400
"""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.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS