how to used try except blocks python code example
Example 1: error handling in python
try:
print(x)
except SyntaxError:
print("There is a SyntaxError in your code")
except NameError:
print("There is a NameError in your code")
except TypeError:
print("There is a TypeError in your code")
Example 2: python: raise error
class MyError(TypeError):
pass
raise MyError('An error happened')