Generic Exception Thrown (ARCH3167)
هذا المحتوى غير متوفر بلغتك بعد.
Key typescript.logging.throw-generic-error · Severity info · Category logging
Throwing the base Error type instead of a specific domain exception forces callers into broad catch blocks. They cannot discriminate by error type.
Incorrect
Section titled “Incorrect”function withdraw(account: Account, amount: number) { if (amount > account.balance) { throw new Error("insufficient funds"); } account.balance -= amount;}Correct
Section titled “Correct”class InsufficientFundsError extends Error {}
function withdraw(account: Account, amount: number) { if (amount > account.balance) { throw new InsufficientFundsError("insufficient funds"); } account.balance -= amount;}Throw a specific domain exception that callers can catch selectively instead of base Error.