try blocktry block, include an except block to handle the problem elegantly, i.e. print an error messagestring and inttry:
# Do your main operations here
'word' + 50
except Exception as e:
# If an exception occurs, print an error message
print('Error: ', e)
Error: must be str, not int
finally block can be used together with try and except blockstry:
# Do your main operations here
'word' + 50
except Exception as e:
# If an exception occurs, print an error message
print('Error: ', e)
finally:
print('Operation finished.')
Error: must be str, not int
Operation finished.