Program to demonstrate multiple catch blocks handling chained exceptions in Java
Output of the program :
import java.io.IOException;
public class ChainedException {
public static void main(String[] args) {
int i = 10;
try {
i = i / 0;
System.out.println("In First try block");
}catch(ArithmeticException ae) {
System.out.println("In First Catch Block");
System.out.println("Arithmetic Exception Handled :\n" + ae);
try {
throw new IOException();
}catch(IOException ioe) {
System.out.println("In Second Catch Block");
System.out.println("IOException Handled :\n" + ioe);
try {
throw new NumberFormatException();
}catch(NumberFormatException nfe) {
System.out.println("In Third Catch Block");
System.out.println("NumberFormatException Handled :\n" + nfe);
}
}
}
}
}
Output of the program :
