Multiple catch blocks
package com.company;
import java.util.Scanner;
public class CWH_81_Specific_Exception {
public static void main(String[] args) {
// Handling Specific exception
int [] marks= new int[3];
marks[0]=45;
marks[1]=78;
marks[2]=98;
System.out.println("Enter the value of index");
Scanner ind=new Scanner(System.in);
int a= ind.nextInt();
System.out.println("Enter the value of number");
Scanner num=new Scanner(System.in);
int b= num.nextInt();
try{
System.out.println("The value at index " + a +" of array is : "+marks[a]);
System.out.println("The value after division is : "+marks[a]/b);
}
catch(IndexOutOfBoundsException e){
System.out.println("Exception is: "+ e);
}
catch(ArithmeticException e1){
System.out.println("Exception is: "+ e1);
}
catch(Exception e){
System.out.println("Some other exception "+e);
}
}
}
Comments
Post a Comment