Q.Write A Program For Multiple Catch To Fire Arrayindexoutofboundsexception and Stringindexoutofboundsexception Both
Q.Write A Program For Multiple Catch To Fire Arrayindexoutofboundsexception and Stringindexoutofboundsexception Both
ANS::-
class MultiCatch
String a="Hello";
int b[]={1,2};
try
char c=a.charAt(10);
System.out.println(c);
for(int i=0;i<3;i++)
System.out.printf("%d\n",b[i]);
catch(StringIndexOutOfBoundsException e)
System.out.println(e);
catch(ArrayIndexOutOfBoundsException e)
System.out.println(e);
}
Q.Write a program to handle the ArithmeticException.
class Example1
try{
int output=num1/num2;
catch(ArithmeticException e){
Q. Define an object reference and initialize it to null. Try to call a method through
this reference. Now wrap the code in a try-catch clause to catch the exception.
class NULL
NULL ob=null;
try
ob.go();
catch(Exception e)
System.out.println(e);
System.out.println("NORMAL FLOW....");
void go()
System.out.println("HELLO WORLD");