Try With Multiple Catch Block
Try With Multiple Catch Block
===============================
try{
}catch(){
}catch(){
Example 1 :
package typesOfExceptionHandling;
int a = 10;
int b = 0;
int c = a / b;
String s = null;
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
}
}
Example 2:
package typesOfExceptionHandling;
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);
String s = null;
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
Example 3:
package typesOfExceptionHandling;
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);
String s = "Santosh";
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
}
}
Example 4:
package typesOfExceptionHandling;
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);
String s = "Santosh";
System.out.println(s.length());
String s1 = "123";
Integer.parseInt(s1);
}
}
Example 5:
package typesOfExceptionHandling;
try {
int a = 10;
int b = 0;
int c = a / b;
System.out.println(c);
String s = null;
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
} catch (Exception e) {
}
}
}
Example 6 :
package typesOfExceptionHandling;
import java.io.FileNotFoundException;
try {
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);
String s = null;
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
} catch (Exception e) {
System.out.println(e);
}
System.out.println("Main method ended");
}
Example :
package typesOfExceptionHandling;
import java.io.FileNotFoundException;
try {
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);
String s = "Santosh";
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
} catch (Exception e) {
System.out.println(e);
}
System.out.println("Main method ended");
}
Example :
package typesOfExceptionHandling;
import java.io.FileNotFoundException;
String s = null;
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
} catch (ArithmeticException e) {
System.out.println(e);
} catch (NullPointerException e) {
System.out.println(e);
} catch (NumberFormatException e) {
System.out.println(e);
}
System.out.println("Main method ended");
}
Example :
package typesOfExceptionHandling;
import java.io.FileNotFoundException;
String s = null;
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
} catch (ArithmeticException e) {
System.out.println(e);
} catch (NullPointerException e) {
System.out.println(e);
} catch (NumberFormatException e) {
System.out.println(e);
}
System.out.println("Main method ended");
}
}
Example :
package typesOfExceptionHandling;
import java.io.FileNotFoundException;
String s = "BIkkadIT";
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
} catch (ArithmeticException e) {
System.out.println(e);
} catch (NullPointerException e) {
System.out.println(e);
} catch (NumberFormatException e) {
System.out.println(e);
}
System.out.println("Main method ended");
}
Example :
package typesOfExceptionHandling;
import java.io.FileNotFoundException;
String s1 = "123Santosh";
Integer.parseInt(s1);
} catch (ArithmeticException e) {
System.out.println(e);
} catch (NullPointerException e) {
System.out.println(e);
} catch (Exception e) {
System.out.println(e);
}
System.out.println("Main method ended");
}
Example : Note While working with multicatch block parent exception always should
be at bottom .
package basicsOfExceptionHandling;
String s = "BIkkadIT";
System.out.println(s.length());
String s1 = "123Santosh";
Integer.parseInt(s1);
} catch (Exception e) {
} catch (ArithmeticException e) {
} catch (NullPointerException e) {
}
System.out.println("Main method ended");
}
}