Multiple Exception Example

import java.util.Scanner;

public class MultipleTestException
{
/* exception example
 */
 public static void main(String args[])  {
  int no1=0, no2=0 ;
 try  {
 no1 = Integer.parseInt(args[0]);
 no2 = Integer.parseInt(args[1]);
 System.out.println("After 2nd argument" );
 }
 catch (ArrayIndexOutOfBoundsException ae)
 {
  System.out.println(ae);
 }
 catch (NumberFormatException ne) {
  System.out.println(ne);

 }
 finally  {
    System.out.println("Resources are released");
 }

  System.out.println("sum  : " + (no1 + no2) );

  try  {
  System.out.println("Division  : " + (no1 / no2) );
  }
  catch (ArithmeticException ae)
  {
   System.out.println(ae.getMessage());
   //System.out.println("Divide by Zero");
  }

 System.out.println("Difference  : " + (no1 - no2) );

 System.out.println("Multiplication  : " + (no1 * no2) );


 }


}

Comments

Popular posts from this blog

Custom Exception example for BankAccount

HashMap HashSet example

Annotation