title: Why do I need to reset the Scanner in a catch block, but not the try block? (Java)
body: <p>I have the following code, where I need the user to input an int &gt; 0.</p>
  <pre><code>    int rows = 0;
      while(rows &lt;= 0){
          System.out.println(&quot;How many rows are in the matrix?&quot;);
          try{
              rows = scan.nextInt();
              if (rows &lt;= 0){
                  System.out.println(&quot;Invalid input, try again&quot;);
                  //scan.nextLine(); // !A!
              }
          } catch(InputMismatchException e){
              System.out.println(&quot;Invalid input, try again&quot;);
              //scan.nextLine(); // !B!
          } 
      }
  </code></pre>
  <p>Why does it work without uncommenting A, but does not work without uncommenting B? In other words, why does the catch block need scan.nextLine(), but the try block does not?</p>
  <p>Aren't both of them printing a new line after? Why does the catch block have this requirement?</p>