CKTIS / Java
lang.ArithmeticException: practical reference
lang.ArithmeticException: practical reference: ArithmeticException signals an exceptional arithmetic condition such as integral division by zero; floating-point division follows IEEE 754.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.lang.ArithmeticExceptionArithmeticException signals an exceptional arithmetic condition such as integral division by zero; floating-point division follows IEEE 754.
Handle ArithmeticException where integer or exact library arithmetic has a defined recovery path.
Integer division by zero throws it, but floating division produces infinity or NaN. Do not depend on its message text.
MIN_VALUE / -1 silently overflows. BigDecimal.divide without a rounding rule can throw for a non-terminating decimal expansion.
The example exercises the documented element in a small deterministic program and compares exact standard output.
Examples
public class Main {
public static void main(String[] args) throws Exception {
try { int value = 1 / 0; } catch (ArithmeticException error) { System.out.println(error.getClass().getSimpleName()); }
}
}
Result
ArithmeticException
The example exercises the documented element in a small deterministic program and compares exact standard output.