How can I check if multiplying two numbers in Java will cause an overflow?

Java 8 has Math.multiplyExact, Math.addExact etc. for ints and long. These throw an unchecked ArithmeticException on overflow.

Leave a Comment