My sample code is as follows:
public class ExceptionsDemo {
public static void main(String[] args) {
try {
int arr[]={1,2,3,4,5,6,7,8,9,10};
for(int i=arr.length;i<10;i++){
if(i%2==0){
System.out.println("i =" + i);
throw new Exception();
}
}
} catch (Exception e) {
System.err.println("An exception was thrown");
}
}
}
My requirement is that, after the exception is caught I want to process the remaining elements of the array. How can I do this?
Your code should look as follows: