Production-Grade Exception Handling Pattern

Mon 10 August 2026
def safe_divide(a, b):
    try:
        return a / b
    except ZeroDivisionError as e:
        return f"Error: {e}"
    except Exception as e:
        return f"Unexpected error: {e}"
    finally:
        print("Operation attempted")

print(safe_divide(10, 0))
Operation attempted
Error: division by zero


Score: 10

Category: chapter6_exception_handling