Multiple catch for try block
This is simple java program which explains how to catch multiple exception .
Remember exception is super class of all exception type . So that code follow sequence
package Exceptions;
import java.io.*;
import java.lang.*;
public class Multiplecatch {
public static void main(String[] args) {
try{
int a[]=new int[5];
a[5]= 29/0;
}
catch(ArithmeticException e)
{
System.out.println("Arithmetic Exception occurs");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexOutOfBounds Exception occurs");
}
catch(Exception e)
{
System.out.println("Parent Exception occurs");
}
System.out.println("rest of the code");
}
}
Program output --
Arithmetic Exception occurs
rest of the code
Try to make print arrayoutof bound exception add code on it.
Multiple catch for try block
Reviewed by Mukesh Jha
on
10:01 AM
Rating:
No comments:
Add your comment