Any class that extends Exception
(with the exception of RuntimeException
) is considered a checked exception. This means that you, the programmer, must either catch it in a try...catch
block, or throw the exception elsewhere.
The problem is that your method enqueue()
throws a checked exception.
You could solve this one of two ways:
- Wrap the call to
enqueue
in atry...catch
block, or - Add
throws OverFlow
tomain
.
Examples of both:
try {
q.enqueue("1");
} catch (OverFlow e) {
e.printStackTrace();
}
public static void main(String[] args) throws OverFlow {
ArrayQueue q=new ArrayQueue();
q.enqueue("1");
}