Java Reference
In-Depth Information
While this approach is easy enough to implement, it is annoying to use. Exceptions are sup-
posed to be for exceptional conditions [EJ Item 39]. “Buffer is full” is not an exceptional
condition for a bounded buffer any more than “red” is an exceptional condition for a traffic
signal. The simplification in implementing the buffer (forcing the caller to manage the state
dependence) is more than made up for by the substantial complication in using it, since now
the caller must be prepared to catch exceptions and possibly retry for every buffer opera-
tion. [1] A well-structured call to take is shown in Listing 14.4 —not very pretty, especially
if put and take are called throughout the program.
Search WWH ::




Custom Search