Java program for customized exception handling(try-catch block)

 import java.util.*;

class A

{

public static void main(String ar[])

{

Scanner sc = new Scanner(System.in);

int a,b;

System.out.println("Enter 1st number: ");

a = sc.nextInt();

System.out.println("Enter 2nd number: ");

b = sc .nextInt();

try 

{

System.out.println(a+"/"+b+" = "+a/b);

catch(ArithmeticException e)

{

System.out.println(a+"+"+b+" = "+a+b);

System.out.println("Thanks");

}

}

}


OUTPUT



Comments