Exception Handling

Python provides try-except blocks for handling errors gracefully.

Snippet:

try:\n    result = 10 / 0\nexcept ZeroDivisionError:\n    print("Cannot divide by zero!")

Example:

try:\n    num = int("abc")\nexcept ValueError:\n    print("Invalid input!")