title: Only accept positive integers using try catch and while
body: <p>I'm writing a script where the user can only input positive integers. I'm using a scanner with try catch and a while loop. The loop is to keep asking the user for a correct input.</p>
  
  <p>I can check for negative integers, but what about strings or some other crazy stuff?</p>
  
  <pre><code>    int price = 0;
      Scanner input = new Scanner(System.in);
      try {
          System.out.println("Enter max price: ");
          price = input.nextInt();
          if (price &gt; 0) {
              input.close();
          } else {
              while (price &lt; 0) {
                  System.out.println("Negative values not allowed");
                  System.out.println("Enter max price: ");
                  price = input.nextInt();
              }
              input.close();
          }
      } catch (InputMismatchException e1) {
  
      }
  </code></pre>
  
  <p>I'm kind of stuck at the catch part..</p>