Try catch error checking python code example
Example 1: python catch all exceptions
try:
raise Exception("Oh no! An error happened!")
except Exception as err:
print("An error was handled")
finally:
print("This runs either way.")
Example 2: try except python
def sum_of(x, y):
try:
print(x + y)
except TypeError:
print("Invalid argument specified.")