Java program for throw keyword

 import java.util.*;

class Demo

{

public static void main(String ar[])

{

Scanner sc = new Scanner(System.in);

int a,b;

System.out.println("Enter first number : ");

a=sc.nextInt();

System.out.println("Enter second number : ");

b=sc.nextInt();

try

{

if(b==0)

{

ArithmeticException ob = new ArithmeticException();

throw ob;

}

System.out.println(a/b);

}

catch(ArithmeticException e)

{

System.out.println("Can't Divide by zero");

}

System.out.println(a+b);

System.out.println("Bye");

}

}



  OUTPUT




Comments