How to Handle a java.lang.ArithmeticException in Java? Last Updated : 21 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In Java programming, the java.lang.ArithmeticException is an unchecked exception of arithmetic operations. This means you try to divisible by zero, which raises the runtime error. This error can be handled with the ArthmeticException. ArithmeticException can be defined as a runtime exception that can occur during an arithmetic operation due to the exceptional condition. ArithmeticException is part of the java.lang package. In this article, we will learn how to handle a java.lang.ArithmeticException in Java. Syntax:try { // Code that may throw an ArithmeticExceptionExample: division by zero, } catch (ArithmeticException e) { // Exception handling code // Handle the ArithmeticException hereThis block is executed when an ArithmeticException is caughtExample: displaying an error message. } finally { // Optional block}Program to Handle a java.lang.ArithmeticException in JavaLet us understand programmatically, to handle a java.lang.ArithmeticException. Java // Java program to handle a java.lang.ArithmeticException public class GfGArithmeticException { // main method public static void main(String[] args) { int dividend = 10; int divisor = 0; try { // attempting division by zero int result = dividend / divisor; // print the result System.out.println("Result: " + result); } catch (ArithmeticException e) { // print the error System.out.println("ArithmeticException occurred: " + e.getMessage()); } finally { System.out.println("This is the example of the ArithmeticException"); } } } OutputArithmeticException occurred: / by zero This is the example of the ArithmeticException Explanation of the above Program:The above Java program is an example of the ArithmeticException. When we try to attempt dividing by zero, then try block raises the exception during the execution of the program.Then catch can take control and handle the exception and print the error of which type Exception can occur in the Java program. Comment More infoAdvertise with us Next Article How to Handle a java.lang.ArithmeticException in Java? S seepanarajvskq Follow Improve Article Tags : Java Java Programs Java-Exceptions Java-Exception Handling Java Examples +1 More Practice Tags : Java Similar Reads Using throw, catch and instanceof to handle Exceptions in Java Prerequisite : Try-Catch Block in Java In Java, it is possible that your program may encounter exceptions, for which the language provides try-catch statements to handle them. However, there is a possibility that the piece of code enclosed inside the 'try' block may be vulnerable to more than one ex 4 min read Java Program to Handle Runtime Exceptions RuntimeException is the superclass of all classes that exceptions are thrown during the normal operation of the Java VM (Virtual Machine). The RuntimeException and its subclasses are unchecked exceptions. The most common exceptions are NullPointerException, ArrayIndexOutOfBoundsException, ClassCastE 2 min read How to handle a java.lang.IndexOutOfBoundsException in Java? In Java programming, IndexOutOfBoundsException is a runtime exception. It may occur when trying to access an index that is out of the bounds of an array. IndexOutOfBoundsException is defined as the RuntimeException. It can be used to find the out-of-bound run-time errors of an array. It is a part of 2 min read Java Program to Handle the Exception Hierarchies Exceptions are the events that occur due to the programmer error or machine error which causes a disturbance in the normal flow of execution of the program and terminates the program. Exception Handling: The process of dealing with exceptions is known as Exception Handling. Hierarchy of Exceptions: 4 min read How to Solve java.lang.IllegalStateException in Java main Thread? An unexpected, unwanted event that disturbed the normal flow of a program is called Exception. Most of the time exception is caused by our program and these are recoverable. Example: If our program requirement is to read data from the remote file locating in U.S.A. At runtime, if a remote file is no 5 min read Like