Exception and Error Handling in Python code example
Example 1: python catch exception
try:
print('Test')
except (SyntaxError, IndexError) as E:
print('Synthax or index error !')
except :
print('Other error !')
else:
print('No error')
finally:
print('Done')
print('Anything else')
Example 2: 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")