Java Program to Handle Arithmetic Exception

Java Program to Handle Arithmetic Exception

Java Program to Handle Arithmetic Exception

// Java program to handle Arithmetic Exception

public class Main {
  public static void main(String[] args) {
    try {
      int a = 10;
      int b = 0;
      int c = 0;

      c = a / b;

      System.out.println("Division is: " + c);
    } catch (ArithmeticException e) {
      System.out.println("Exception: " + e);
    }

    System.out.println("Program Finished");
  }
}
Exception: java.lang.ArithmeticException: / by zero
Program Finished

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment