When built-in exception types do not describe your error precisely, create your own by extending Exception (for checked) or RuntimeException (for unchecked):
public class InsufficientFundsException extends Exception {
private double amount;
public InsufficientFundsException(double amount) {
super("Insufficient funds: " + amount);
this.amount = amount;
}
public double getAmount() {
return amount;
}
}
Your custom exception passes a message to the parent constructor with super(). You can add extra fields to carry information about the error. The caller catches InsufficientFundsException by name and can call getAmount() to learn how much was short.