Data Science Portfolio

Exception Handling

Try and Except

Try to add a string and int

try:
    # 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

try:
    # 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.