Monday, January 20, 2014

Java Program to illustrate Multiple Catch Exception

with 0 Comment
import java.io.*;
class multiplecatch
{
public static void main(String args[])
{
try
{
int a=args.length;
int c=40;
int b=c/a;
int d[]={5,6,7};
d[6]=10;
}
catch(Arithmetic Exception ae)
{
System.out.println("\n Without Passing Arguments");
System.out.println("\n------------------------");
System.out.println("Exception:Division by zero Error");
}
catch(ArrayIndexOutOfBoundsException ie)
{
System.out.println("\n Passing Arguments");
System.out.println("\n-----------------");
System.out.println("Exception: Array Out of Range");
}
System.out.println("After try-catch block");
}
}

-------------
OUTPUT:
-------------
D:\IIMCA\11MCA13>java multiplecatch

Without Passing Arguments
----------------------------------
Exception: Division by Zero Error
After try-catch block
D:\IIMCA\11MCA13>java multiplecatch 2 15

Passing Arguments
-----------------------
Exception: Array Out of Range
After Try-catch block

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive