public class ExceptionTest { public static boolean checkIntValueForMultiplication(int i, int j) { // einer von beiden Multiplikanten negativ -> Ergebnis negativ if ((i < 0 || j < 0) && !(i < 0 && j < 0)) { if ((j < 0 && j < Integer.MIN_VALUE / Math.abs((double) i)) || (i < 0 && i < Integer.MIN_VALUE / Math.abs((double) j))) { try { throw new IntValueException( "Minimaler Integer-Wert unterschritten!"); } catch (IntValueException e) { System.err.println(e.getMessage()); } return false; } } // beide Multiplikanten negativ -> Ergebnis positiv if (i < 0 && j < 0) { if (j < Integer.MIN_VALUE / -i || i < Integer.MIN_VALUE / -j) { try { throw new IntValueException( "Maximaler Integer-Wert \u00FCberschritten!"); } catch (IntValueException e) { System.err.println(e.getMessage()); } return false; } } // beide Multiplikanten positiv -> Ergebnis positiv if (i > 0 && j > 0) { if (j > Integer.MAX_VALUE / i || i > Integer.MAX_VALUE / j) { try { throw new IntValueException( "Maximaler Integer-Wert \u00FCberschritten!"); } catch (IntValueException e) { System.err.println(e.getMessage()); } return false; } } return true; } public static void main(String[] args) { int i = -70000, j = 70000; if (checkIntValueForMultiplication(i, j)) System.out.println(i * j); } } class IntValueException extends Exception { String s; public IntValueException() { this(null); } public IntValueException(String s) { super(s); this.s = s; } }