Try Catch
public class TryCatchDemo{
// Handling Exception using try-catch blocks
public static void main(String args[]){
try{
int a[] = new int[2];
System.out.println("Access element three :" a[3]);
}catch(ArrayIndexOutOfBoundsException e){ //ArrayIndexOutOfBoundsException is caught here
System.out.println("Exception thrown :" + e);
}
System.out.println("Out of the block");
}
}
Output:
Exception thrown :java.lang.ArrayIndexOutOfBoundsException: 3
Out of the block