Skip to content

Generic Exception Thrown (ARCH2167)

Key python.logging.throw-generic-exception · Severity warning · Category logging

Raising the base Exception type instead of a specific domain exception forces callers into broad except Exception blocks. This makes it impossible to distinguish failures by type.

def withdraw(account, amount):
if amount > account.balance:
raise Exception("Insufficient funds")
class InsufficientFundsError(Exception):
pass
def withdraw(account, amount):
if amount > account.balance:
raise InsufficientFundsError("Insufficient funds")

Define and raise a specific domain exception type so callers can catch it selectively.