/*********************************************************************
*  CreatingExceptions.java       Author: Lewis/Loftus
*  Listing 10.5  Page 543  
*  Modified by e. adams
*
*  Demonstrates the ability to utilize a user-defined exception
*  This class creates a user-defined Exception object which may
*  or may not be thrown.
*/
import java.util.Scanner;

public class CreatingExceptions
{
   public static void main (String[] args) throws OutOfRangeException
   {
	     // these constants are being declared just to illustrate
		  // the throwing of the user defined exception
      final int MIN = 25;    
		final int MAX = 40;

      int value;

      Scanner scan = new Scanner (System.in);

          // declaration of the user defined Exception object
      OutOfRangeException problem;
		
		    // instantiation of the user defined Exception object 
			 // with the required String parameter
		problem  = new OutOfRangeException ("Input value is out of range.");

          // prompt for user input to test the program
      System.out.print 
		("Enter an integer value between " + MIN + " and " + MAX + ", inclusive: ");

         // picking up the user's input 		
      value = scan.nextInt();
		
		   // echo of the user's input
		System.out.println (" the value you entered was " + value);

      //  Determine if the exception should be thrown
      if (value < MIN || value > MAX)
         throw problem;

        /* because there is no try catch block the following
		     statement may never be reached. It will only be printed 
		     if the value entered by the user is in the desired range
		  */
      System.out.println ("End of main method.");  // may never reach
   }
}
