public class ExceptionDemo1
{
public static void main(String[] args)
{
int a = 10;
int b = 0;
int c = a / b;
System.out.println("Welcome");
System.out.println("Hello");
}
}
Output Exception in thread "main" java.lang.ArithmeticException: / by zero
at ExceptionDemo1.main(ExceptionDemo1.java:8)
ExceptionDemo2.java public class ExceptionDemo2
{
public static void main(String[] args)
{
int a = 10;
int b = 0;
try
{
int c = a / b;
}
catch (ArithmeticException arithmeticException)
{
System.out.println("Divided by zero is not possible");
}
System.out.println("Welcome");
System.out.println("Hello");
}
}