/* TestException7.java CIS 260 Dave Klick 2016-02-03 This program shows how you can throw an exception which includes a message, handle the exception, and display the message. */ public class TestException7 { public static void main(String[] args) { for (int i=0; i<10; i++) { try { generateException(i); System.out.println("Passed: " + i); } catch (MyException e) { System.out.println("Exception: " + e.getMessage()); } } } private static void generateException(final int n) throws MyException { if (n % 2 != 0) throw new MyException(n + " is not an even number"); } } class MyException extends Exception { public MyException() {} public MyException(String msg) { super(msg); } }