Aller au contenu

Generic Exception Thrown (ARCH2167)

Ce contenu n’est pas encore disponible dans votre langue.

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.