Java : ArithmeticException - API Examples
ArithmeticException (Java SE 19 & JDK 19) API Examples.
You will find code examples on most ArithmeticException methods.
Summary
try {
final var ret = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("ArithmeticException! : " + e.getMessage());
}
// Result
// ↓
//ArithmeticException! : / by zero
try {
final var ret = Math.addExact(Integer.MAX_VALUE, 1);
} catch (ArithmeticException e) {
System.out.println("ArithmeticException! : " + e.getMessage());
}
// Result
// ↓
//ArithmeticException! : integer overflow
Constructors
ArithmeticException ()
final var e = new ArithmeticException();
System.out.println(e); // java.lang.ArithmeticException
ArithmeticException (String s)
final var e = new ArithmeticException("abcde");
System.out.println(e); // java.lang.ArithmeticException: abcde
System.out.println(e.getMessage()); // abcde
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Please see the link below.
Related posts
- API Examples