Use try/except to handle errors gracefully. Catch specific exceptions like ValueError or FileNotFoundError. The finally block always runs for cleanup. Raise exceptions with raise and create custom ones with class.
Handling Exceptions
try:
result = 10 / 0
except ZeroDivisionError as e:
print(f"Error: {e}")
except (TypeError, ValueError):
print("Wrong type or value")
else:
print("No exception!")
finally:
print("Always runs")
# Raise custom exception
raise ValueError("Bad input")