Programs on exception handling (catching invalid command line arguments try with multiple catch blocks).

Code:

class err6

 

{

 

public static void main(String[] args) { int i;

 

try

 

{

 

System.out.println("Command line arguments are:");

for (i=0;i<5 ;i++ )

 

{

 

System.out.println(Integer.parseInt(args[i]));

 

}

}

 

catch(NumberFormatException e)

 

{

 

System.out.println("Invalid data."); System.out.println("Type of error:"+e);

}

 

catch(ArrayIndexOutOfBoundsException e1)

 

{

 

System.out.println("Array overflow."); System.out.println("Type of error:"+e1);

 

}

 

finally

 

{

System.out.println("I am always there.");

 

}

}

 

}

Output:-

Programs on exception handling (catching invalid command line arguments try with multiple catch blocks).

Post a Comment

0 Comments