Exception Class DivideByZeroException [code] public class DivideByZeroException extends ArithmeticException { public DivideByZeroException() { super("Attempted to divide by zero!"); } }Tester Class ExceptionTester
public class ExceptionTester { private static int quotient(int numerator, int denominator) throws DivideByZeroException { if(denominator == 0) throw new DivideByZeroException(); return(numerator / denominator); } public static void main(String args[]) { int number1=0, number2=0, result=0; try { number1 = 1; number2 = 0; result = quotient(number1,number2); System.out.print(number2 + " goes into " + number1); System.out.println(" this many times: " + result); } catch (Exception e) { System.out.println(e.toString()); System.out.println("An Exception occured"); System.exit(-1); } } }[/code]