This is my array implementation of stack code:
public class ArrayStack2{
private final int DEFAULT_SIZE=10;
public int tos;
Object[] array;
public ArrayStack2(){
array =new Object[DEFAULT_SIZE];
tos=-1;
}
public void push(Object e){
try{
array[tos+1]=e;
tos++;
}
catch(OverFlowException e1){
e1.print();
}
}
and this is OverFlowException class:
public class OverFlowException extends Exception{
public OverFlowException(){
super();
}
public OverFlowException(String s){
super(s);
}
public void print(){
System.out.println("OverFlow");
}
}
When I run this compiler gives the error "exception OverFlowException is never thrown in body of corresponding try statement "
then I realized I have not included the part to check if the array isFull().
My question is I have isFull() method in ArrayStack2 class and how can i call it from OverFlowException class.
Please help me to find a way to correct this exception problem