Exception Handling Java Program – Dynamic Inputs

By | December 4, 2010
Exception Handling Java Program. You can give the input dynamically and can check it.

Exception Handling Java Program. You can give the input dynamically and can check it.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Excepdemo {
/**
* @param args
*/
public static void main(String[] args) {
int ary[]={1,2,3};
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter number”);
int a = Integer.parseInt(br.readLine());
System.out.println(“Enter number”);
int b = Integer.parseInt(br.readLine());
int c=a/b;
System.out.println(ary[10]);
}catch (ArithmeticException e) {
System.out.println(e);
}catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e);
}
/* catch (NumberFormatException e) {
System.out.println(e);
} */
catch (IOException e) {
System.out.println(e);
}
catch(Exception e)
{
System.out.println(“u have done a mistake.”);
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *