code: public static int safeMultiply(int a, int b) {
          long total = (long) a * (long) b;
          if (total < Integer.MIN_VALUE || total > Integer.MAX_VALUE) {
              throw new ArithmeticException("Multiplication overflows an int: " + a + " * " + b);
          }
          return (int) total;
      }
docs: Safely multiply one int by another.
  
  @param a  the first value
  @param b  the second value
  @return the result
  @throws ArithmeticException if the result overflows an int