Python supports try and except statements.
Based on the actions performed inside try, if there is an exception, the corresponding exception is executed. Then, if there is an else block, it is executed and then finally block is executed if it is present.
a = 100
try:
print(a)
except:
print("Error")
else:
print("Just print")
finally:
print("Metric Coder")
try:
print(b)
except NameError:
print("Name error")
except:
print("Error")
finally:
print("Finally wow!")
if a > -1:
raise Exception("Positive value...")
The link to the Github repository is here .