title: How can I create an exception that checks for int range, number type, and not a char?
body: <p>I'm trying to wrap my head around exceptions and the problem I'm running into is that I'm being required to create a program that asks for user input for a number 9-99.  This number must be error-checked using 3 different exceptions.</p>
  
  <blockquote>
    <p>e1: number is outside of the range (200)</p>
    
    <p>e2: number is of a data type other than integer (double)</p>
    
    <p>e3: input is another data type other than number (char)</p>
  </blockquote>
  
  <p>I have tried to create patterns in my if structure to make all three work, however I can't get it to differentiate between e2 and e3.  It will always default to e2.  This is what I have with only two exceptions, but I would greatly appreciate help with figuring out how to implement the third.  Thank you.</p>
  
  <pre><code>public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      boolean tryAgain = true;
    do {
         try {
              System.out.println("Please enter an integer between 9 and 99: ");
  
              int inInt = input.nextInt();
  
              if (inInt &gt;= 9 &amp;&amp; inInt &lt;= 99){
                  System.out.println("Thank you.  Initialization completed.");
                  tryAgain = false;
              }
              else if (inInt &lt; 9 || inInt &gt; 99){
                  throw new NumberFormatException("Integer is out of range.");
              }
          }
          catch (NumberFormatException e1) { // Range check
              System.out.println("* The number you entered is not between 9 and 99.  Try again.");
              System.out.println();
              input.nextLine();
          }
         catch (InputMismatchException e2) { // Something other than a number
              System.out.println("* You did not enter an integer.  Try again.");
              System.out.println();
              input.nextLine();
          }
      } while(tryAgain);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the output I get right now:</p>
  
  <blockquote>
    <blockquote>
      <p>Please enter an integer between 9 and 99: 
      2</p>
      
      <ul>
      <li>The number you entered is not between 9 and 99.  Try again.</li>
      </ul>
      
      <p>Please enter an integer between 9 and 99: 
      f</p>
      
      <ul>
      <li>You did not enter an integer.  Try again.</li>
      </ul>
      
      <p>Please enter an integer between 9 and 99: 
      88</p>
      
      <p>Thank you.  Initialization completed.</p>
    </blockquote>
  </blockquote>
  
  <p><a href="https://www.ideone.com/ZiOpGH" rel="nofollow noreferrer">https://www.ideone.com/ZiOpGH</a></p>