ex.py
l = [2,4,5,8]
try:
l[5]
except NameError as ex:
print('Error message:', ex)
except Exception as ex: #Catch other exceptions (although this usage is not recommended)
print('Error message:',ex)
else:
print('Only executed if successful')
finally:
print('Will always be executed')
Recommended Posts