public class Account {
int money;
public Account(int money) {
this.money = money;
}
public void withdraw(int amount) throws InsufficientFundsException {
if (amount > money) {
throw new InsufficientFundsException("余额不足!" + "取款额度:" + amount + "实际额度:" + money);
}
money -= amount;
}
}
class Client {
public static void main(String[] args) {
Account a = new Account(500);
try {
a.withdraw(1000);
} catch (InsufficientFundsException e) {
e.printStackTrace();
}
}
}
class InsufficientFundsException extends Exception {
public InsufficientFundsException(String s) {
super(s);
}
}