import java.util.*;
class ArrayOverflowException extends Exception{
ArrayOverflowException(){
super();
}
static int i;
static void check(int i) throws ArrayOverflowException{
if (i>5) {
throw new ArrayOverflowException("Array Overflow");
return;
}
}
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int a[]=new int[5];
System.out.println("Enter the elemets of the array. #MAX 6 ELEMENTS#");
try{
for (int i=0;i<10;i++) {
ArrayOverflowException.check(i);
a[i]=input.nextInt();
}
}catch (ArrayOverflowException e) {
System.out.println("Exception handled"+e);
}
}
}
I have been trying to create my own user defined exception in Java that gives an error cannot find symbol in line 9
. Please help.
Line 9 is throw new ArrayOverflowException("Array Overflow");