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.
Comments
Leave a comment