title: Java try-catch input validation with do-while loop
body: <p>I've been sitting here (embarrassingly) for hours trying to get a do-while loop to to accept user input until it's valid, but I seem to be messing up when it comes to the boolean that I'm using to try and exit the loop.  Whenever I can get the program to partially work the catch exception just ends up repeating itself infinitely.</p>
  
  <pre><code>Scanner scnr = new Scanner(System.in);
  
  double wallHeight = 0.0;
  boolean valid = false;
  
  // Implement a do-while loop to ensure input is valid
  // Prompt user to input wall's height
  do {
      try {
          System.out.println("Enter wall height (feet): ");
          wallHeight = scnr.nextDouble();
          valid = false;
  
          if (wallHeight &lt;=0) {
              throw new Exception ("Invalid Input");
          }
      }
      catch (Exception e) {
          System.out.println("Invalid Input");
      }
  } while (!valid);
  </code></pre>