title: Java Exception throw creates an infinite loop
body: <p>I have established a do-while loop to verify user input is valid.  If a 0 or negative number is entered, the Exception is thrown and the catch prints out.  However, if a string is entered (i.e., twenty instead of 20) it becomes an infinite loop constantly printing out &quot;Invalid input!!&quot;, asking for user input, and printing out &quot;Invalid input!!&quot; again. Here's my code:</p>
  <pre><code>    import java.util.Scanner;
  
  public class Paint {
      public static void main(String[] args) {
          // Create object for the scanner class
          Scanner scnr = new Scanner(System.in);
          
          //Declare variables
          double wallHeight = 0.0;
          double wallWidth = 0.0;
          double wallArea = 0.0;
          double gallonsPaintNeeded = 0.0;
          final double squareFeetPerGallons = 350.0;
          
          //Implement a do-while loop to verify user provides valid input
          do {
              try {
                  //Prompt user for wall's height in feet
                  System.out.println(&quot;Enter wall height (feet): &quot;);
                  wallHeight = scnr.nextDouble();
                  
                  //Verify wallHeight is not less than or equal to zero
                  //If so, throw an exception
                  if(wallHeight &lt;= 0) {
                      throw new Exception();
                  }
              }
              catch(Exception e) {
                  
                  //Print invalid message
                  System.out.println(&quot;Invalid input!!&quot;);
              }
          }
          while(wallHeight &lt;= 0);
          
          //Implement a do-while loop to verify user provides valid input
          
          do {
              try {
                  //Prompt user for wall's width in feet
                  System.out.println(&quot;Enter wall width (feet):&quot;);
                  wallWidth = scnr.nextDouble();
                  
                  //Verify wallWidth is not less than or equal to zero
                  //If so, throw an exception
                  if(wallWidth &lt;= 0) {
                      throw new Exception();
                  }
              }
              catch(Exception e) {
                  
                  //Print invalid message
                  System.out.println(&quot;Invalid input&quot;);
                  
              }
          }
          while(wallWidth &lt;= 0);
          
          //Calculate wallArea
          wallArea = wallHeight * wallWidth;
          
          //Print wallArea
          System.out.println(&quot;Wall area: &quot; + wallArea + &quot; square feet&quot;);
          
          //Calculate gallonsPaintNeeded
          gallonsPaintNeeded = wallArea / squareFeetPerGallons;
          
          //Print paint needed
          System.out.println(&quot;Paint needed: &quot; + gallonsPaintNeeded + &quot; gallons&quot;);
      }
  
  }
  </code></pre>