Throw
public class ThrowDemo {
public static void main(String[] args) {
int[] a=new int[]{1,2};
for(int i=0;i<3;i++){
if(i==3){
throw new ArrayIndexOutOfBoundsException();
}
System.out.println(a[i]);
}
}
}
Output:
1
2
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2