2.Never use exceptions for
flow control
nGenerating
stack traces is expensive and the value of a stack trace is in debugging. In a
flow-control situation, the stack trace would be ignored, since the client just
wants to know
how to proceed.
n
npublic void
useExceptionsForFlowControl() {
n try {
n while(true) { increaseCount(); }
n } catch (MaximumCountReachedException ex) {
n } //Continue execution
n}
n
npublic void increaseCount()
throws MaximumCountReachedException { if (count >=
5000) throw new MaximumCountReachedException();
n}