Answer to Question #283955 in Python for solokin

Question #283955

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
Expert's answer
2022-01-02T02:20:37-0500
1)
Code:

try:
a = 1/0
print(a)
except ZeroDivisionError:
print("Zero!")

Output:

Zero!

2)
Code:

try:
a = []
print(a[1])
except IndexError:
print("Index error")

Output:

Index error


3)


Code:

try:
A = 42
A = A + ' 4 '
except TypeError:
print('Wrong type')

Output:

Wrong type


Another opportunity to deal with this errors is better development and design process. Because of algorithm work good, but there are still error, it's problem with input. So, all input data should be filtered, to prevent wrong input. It means filtering by type, size, value.


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