I hava a program that works and catches the error, however I am looking to make it finish the loop and not stop when the error is caught.
public class myClass {
int[] table;
int size;
public myClass(int size) {
this.size = size;
table = new int[size];
}
public static void main(String[] args) {
int[] sizes = {5, 3, -2, 2, 6, -4};
myClass testInst;
try {
for (int i = 0; i < 6; i++) {
testInst = new myClass(sizes[i]);
System.out.println("New example size " + testInst.size);
}
}catch (NegativeArraySizeException e) {
System.out.println("Must not be a negative.");
}
}
}
The error happens as the array size is negative, but how do I then continue to finish the loop?