![]() |
VOOZH | about |
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.
try {
// Code that may throw an ArithmeticException
Example: division by zero,
} catch (ArithmeticException e) {
// Exception handling code
// Handle the ArithmeticException here
This block is executed when an ArithmeticException is caught
Example: displaying an error message.
} finally {
// Optional block
}
Let us understand programmatically, to handle a java.lang.ArithmeticException.
ArithmeticException occurred: / by zero This is the example of the ArithmeticException