title: Where to put exception for Java Guessing Game
body: <p>Hi I'm currently having trouble throwing exceptions on my guessing game code. I want to put an exception for string input (instead of int) and also an exception for entering a number beyond the limit(50). Thanks.</p>
  
  <pre><code>public static void main (String[] args)
  
  {
      Random ran = new Random();
      int numberToGuess = ran.nextInt(50)+1;
      int numberOfTries = 0;
      Scanner input = new Scanner (System.in);
      int guess;
      boolean win = false;
  
      while (win == false)
      {
          System.out.println("Guess a number from 1 to 50!");
          guess = input.nextInt();
          numberOfTries++;
  
          if (guess == numberToGuess)
          {
              win = true;
          }
          else if (guess &lt; numberToGuess)
          {
              System.out.println("Too low. Try again.");
          }
          else if (guess &gt; numberToGuess)
          {
              System.out.println("Too high. Try again.");
          }
      }
  
      System.out.println("You got it in " + numberOfTries + " attempt(s)!");
  
  }
  </code></pre>