CustomExceptionUsagepublic class CustomExceptionUsage extends Object Just demo code to check syntax of in book examples. |
Fields Summary |
---|
private boolean | approvedHolds whether transaction is approved or not. | private boolean | validCardHolds whether the card is valid or not. |
Methods Summary |
---|
public void | billCard(java.lang.String cardNumber, java.util.Date expiration, java.lang.Float amount)The poor practice of using multiple empty exception classes.
// verify card type and expiration ...
if (!validCard) {
throw new BillingException();
}
// checking code ...
if (!approved) {
System.err.println(cardNumber + "\t" + expiration + "\t" + amount);
throw new CreditCardDeclinedException();
}
| public void | billCard2(java.lang.String cardNumber, java.util.Date expiration, java.lang.Float amount)Using custom exceptions with error codes.
// verify card type and expiration ...
if (!validCard) {
throw new MyCustomException(MyCustomException.BILLING_ERROR);
}
// checking code ...
if (!approved) {
System.err.println(cardNumber + "\t" + expiration + "\t" + amount);
throw new MyCustomException(MyCustomException.CREDIT_CARD_DECLINED);
}
| public boolean | checkForApproval()Checks for card approval.
return true;
|
|