title: Possible exception if User enters String instead of Int
body: <p>I am just playing with Java.I'm trying to force my program to only accept 3 digit numbers.
  I believe I have successfully done this using a while loop (please correct me if I'm wrong).
  But how do I go about printing an error statement if the user enters a string. eg: "abc".</p>
  
  <p>My code:</p>
  
  <pre><code>    import java.util.Scanner;
      public class DigitSum {
  
      public static void main(String[] args) {
  
      Scanner newScan = new Scanner(System.in);
  
          System.out.println("Enter a 3 digit number: ");
          int digit = newScan.nextInt();
  
          while(digit &gt; 1000 || digit &lt; 100)
              {           
               System.out.println("Error! Please enter a 3 digit number: ");
               digit = newScan.nextInt();
              }
  
          System.out.println(digit);
         }
      }
  </code></pre>