Java Exception Handling- Array index out of bound exception example

Throwable->Exception->ArithmeticException
Throwable->Exception->ArrayIndexOutofBounds
Throwable->Exception->StringIndexOutofBounds

// Example of Array index  out of bound exception


class Test
{

public static void main(String ar[])
{

int a=Integer.parseInt(ar[0]);
int b=Integer.parseInt(ar[1]);
int sum=a+b;
System.out.println("Res="+sum);



}


}

//output

C:\JAVA>java Test 10 5
Res=15

C:\JAVA>java Test 10
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
       at Test.main(Test.java:9)

Reactions: