Exceptions cause your application to crash. Handling them allows you to recover gracefully and keep your application running. Learn how to handle exceptions, find what exceptions you should be handling, and exit gracefully in this lesson. You will also learn how you should not handle exceptions and when it is better to let your application crash rather than swallowing an exception.
import sys# print(int(sys.argv[1]) / int(sys.argv[2]))try: print(int(sys.argv[1]) / int(sys.argv[2]))except ValueError as e: print('You must enter a valid number')except ZeroDivisionError as e: print("You can't divide by zero")
Built in:
Requests: