Java Reference
In-Depth Information
A
QueueEmptyException
will be generated when an attempt is made to remove an
element from an empty queue.
3
. Modify the
FixedQueue
class so that it throws exceptions when an error occurs, as
shown here. Put it in a file called
FixedQueue.java
.
Notice that two steps are required to add exceptions to
FixedQueue
. First,
get( )
and
put( )
must have a
throws
clause added to their declarations. Second, when an error
occurs, these methods throw an exception. Using exceptions allows the calling code
to handle the error in a rational fashion. You might recall that the previous versions
simply reported the error. Throwing an exception is a much better approach.