Exception handling with Multiple statements

PHOTO EMBED

Sat Apr 22 2023 12:21:31 GMT+0000 (Coordinated Universal Time)

Saved by @Sai_Koushik

public class Hello {

	public static void main(String[] args) {

		int i = 2;                    //dividing btwo values
		int j = 0;
        String str = null;           //defing string value as null
 
int nums [] = new int [5];  //  size of arrow is 5 but index numbers will 4 so we can print until 4 only and by defualt their values output is 0




 try{
	 

	j = 18/i ;
	System.err.println(j);
    System.out.println(nums[1]) ;          //print index value 4 value which will be 0  as no value defined
	System.out.println(nums[4]);      //print index value 4 value which will be 0  as no value defined
	System.out.println(str.length());     //******trying to print length of null - throws exception  ***********************

}


	catch (ArithmeticException e) {

 System.out.println("Error form dividing value with denominator O ");         

}

catch(ArrayIndexOutOfBoundsException e) {

	System.out.println("Array error ");   

}

catch(Exception e) {

	System.out.println("Error Unknown" + e);     //printing statement with name of Exception class

}


System.out.println("Koushik is working on Exception Handling");


}
}
content_copyCOPY