0% found this document useful (0 votes)
9 views

Try With Multiple Catch Block

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Try With Multiple Catch Block

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Try With Multiple Catch Block :

===============================
try{

}catch(){

}catch(){

Example 1 :

package typesOfExceptionHandling;

public class TryCatchFinallyBlockDemo {

public static void main(String[] args) {

System.out.println("Main method started");

int a = 10;
int b = 0;
int c = a / b;

String s = null;
System.out.println(s.length());

String s1 = "123Santosh";
Integer.parseInt(s1);

System.out.println("Main method ended");

}
}

Example 2:

package typesOfExceptionHandling;

public class TryCatchFinallyBlockDemo {

public static void main(String[] args) {

System.out.println("Main method started");

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);

System.out.println("Main method ended");


}
}

Example 3:

package typesOfExceptionHandling;

public class TryCatchFinallyBlockDemo {

public static void main(String[] args) {

System.out.println("Main method started");

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);

System.out.println("Main method ended");

}
}

Example 4:

package typesOfExceptionHandling;

public class TryCatchFinallyBlockDemo {

public static void main(String[] args) {

System.out.println("Main method started");

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);

System.out.println("Main method ended");

}
}
Example 5:

package typesOfExceptionHandling;

public class TryCatchFinallyBlockDemo {

public static void main(String[] args) {

System.out.println("Main method started");

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);

System.out.println("Main method ended");

} catch (Exception e) {

}
}
}

Example 6 :

package typesOfExceptionHandling;

import java.io.FileNotFoundException;

public class Demo extends Object {

public static void main(String[] args) {

System.out.println("Main method started");

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);

System.out.println("Main method ended");

} catch (Exception e) {
System.out.println(e);
}
System.out.println("Main method ended");
}

Example :

package typesOfExceptionHandling;

import java.io.FileNotFoundException;

public class Demo extends Object {

public static void main(String[] args) {

System.out.println("Main method started");

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);

System.out.println("Main method ended");

} catch (Exception e) {
System.out.println(e);
}
System.out.println("Main method ended");
}

Example :

package typesOfExceptionHandling;

import java.io.FileNotFoundException;

public class Demo extends Object {

public static void main(String[] args) {

System.out.println("Main method started");


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);

System.out.println("Main method ended");

} 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;

public class Demo extends Object {

public static void main(String[] args) {

System.out.println("Main method started");


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);

System.out.println("Main method ended");

} 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;

public class Demo extends Object {

public static void main(String[] args) {

System.out.println("Main method started");


try {
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);

String s = "BIkkadIT";
System.out.println(s.length());

String s1 = "123Santosh";
Integer.parseInt(s1);

System.out.println("Main method ended");

} 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;

public class Demo extends Object {

public static void main(String[] args) {

System.out.println("Main method started");


try {
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);
String s = "BIkkadIT";
System.out.println(s.length());

String s1 = "123Santosh";
Integer.parseInt(s1);

System.out.println("Main method ended");

} 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;

public class Demo {

public static void main(String[] args) {

System.out.println("Main method started");


try {
int a = 10;
int b = 2;
int c = a / b;
System.out.println(c);

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");
}
}

You might also like