Common Exception Types

Example Usage

Example 1: Basic try-except

try:
    x = int(input("Please enter a number: "))   
except ValueError:
    print("That's not a valid number!")

This example attempts to convert user input into an integer. If the input is not a valid number, it raises a ValueError, which is caught and handled by printing an error message.