FileDocCategorySizeDatePackage
CustomExceptionUsage.javaAPI DocExample3068Sun Dec 14 22:47:38 GMT 2003oreilly.hcj.exceptions

CustomExceptionUsage

public class CustomExceptionUsage extends Object
Just demo code to check syntax of in book examples.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.4 $

Fields Summary
private boolean
approved
Holds whether transaction is approved or not.
private boolean
validCard
Holds whether the card is valid or not.
Constructors Summary
Methods Summary
public voidbillCard(java.lang.String cardNumber, java.util.Date expiration, java.lang.Float amount)
The poor practice of using multiple empty exception classes.

param
cardNumber Cutomer's card number.
param
expiration Expiration date of the card.
param
amount Amount to bill.
throws
BillingException If an error in the billing occurs.
throws
CreditCardDeclinedException If the card is declined.


	                                           	 
	       
	       
		// 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 voidbillCard2(java.lang.String cardNumber, java.util.Date expiration, java.lang.Float amount)
Using custom exceptions with error codes.

param
cardNumber Cutomer's card number.
param
expiration Expiration date of the card.
param
amount Amount to bill.
throws
MyCustomException If there is some problem billing the card.

		// 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 booleancheckForApproval()
Checks for card approval.

return
True if approved, false otherwise.

		return true;