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.
Incorrect
Section titled “Incorrect”def withdraw(account, amount): if amount > account.balance: raise Exception("Insufficient funds")Correct
Section titled “Correct”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.