// ******************************************************************** // CreatingExceptions.java Author: Lewis and Loftus // // Demonstrates the ability to define an exception via inheritance. //******************************************************************** import java.util.Scanner; public class CreatingExceptions { //----------------------------------------------------------------- // Creates an exception object and possibly throws it. //----------------------------------------------------------------- public static void main(String[] args) throws OutOfRangeException { final int MIN = 25, MAX = 40; OutOfRangeException problem = new OutOfRangeException("Input value is out of range."); System.out.print("Enter an integer value between " + MIN + " and " + MAX + ", inclusive: "); Scanner input = new Scanner(System.in); int value = input.nextInt(); // Determines if the exception should be thrown if (value < MIN || value > MAX) throw problem; System.out.println("End of main method."); // may never reach } }