title: Throw an error when a string is entered instead of an int
body: <p>I am working on homework for my class. I have written a method to throw an error if an incorrect integer is entered and I am trying to give an error message when a string is entered instead of an int but I am not sure how. I am not allowed to use parsInt or built in string methods. I would be grateful for any help.</p>
  
  <pre><code>int playerNum = stdin.nextInt();
  while (invalidInteger(playerNum) == -1 || invalidInteger(playerNum) == -2 || invalidInteger(playerNum) == -3)
  {
      if(invalidInteger(playerNum) == -1)
      {
          System.out.println("Invalid guess. Must be a positive integer.");
          System.out.println("Type your guess, must be a 4-digit number consisting of distinct digits.");
          count++;
      }
      if(invalidInteger(playerNum) == -2)
      {
          System.out.println("Invalid guess. Must be a four digit integer.");
          System.out.println("Type your guess, must be a four digit number consisting of distinct digits.");
          count++;
      }
      if(invalidInteger(playerNum) == -3)
      {
          System.out.println("Invalid guess. Must have distinct digits.");
          System.out.println("Type your guess, must be a four digit number consisting of distinct digits.");
          count++;
      }
      playerNum = stdin.nextInt();
  }
  </code></pre>
  
  <p>Added this snippet to catch the exception. Thanks to almas shaikh.</p>
  
  <pre><code>try {
      int playerNum = scanner.nextInt();
      //futher code
  } catch (InputMismatchException nfe) {
      System.out.println("You have entered a non numeric field value");
  }
  </code></pre>