何时应该创建受控异常,何时应该创建运行时异常?
例如,假设我创建了以下类:
public class Account { private float balance; /* ... constructor, getter, and other fields and methods */ public void transferTo(Account other, float amount) { if (amount > balance) throw new NotEnoughBalanceException(); /* ... */ } }
我该如何创建我的NotEnoughBalanceException?它应该扩展异常还是RuntimeException?或者我应该只使用IllegalArgumentException ?