title: Repeating error message inside a while loop
body: <p>I'm currently working my way through a Udemy Java course and am practicing what i have learnt thus far.</p>
  
  <p>I have the following simple program which i am planning on using to get the user to input his name.</p>
  
  <pre><code>import java.util.Scanner;
  
  
  
  public class Adventure {
      public static final int menuStars = 65;
      private static Scanner input = new Scanner(System.in);
  
      public static void main(String[] args) {
          String firstName = "";
          String lastName = "";
          boolean validName = false;
          while(!validName){
              //Entering first name
              System.out.println("Please enter your first name.");
              try {
                  firstName = input.nextLine();
                  if(firstName.length() == 0){
                      throw new Exception("Please enter a first name of at least 1 character.");  
                  }else{
                      //Entering last name
                      System.out.println("Please enter your last name.");
                      lastName = input.nextLine();
                      if(lastName.length() == 0){
                          throw new Exception("Please enter a last name of at least 1 character");
                      }else{
                          System.out.println("You have entered " + firstName +" " + lastName);
                      }
  
                  }
              } catch (Exception e) {
                  System.out.println(e.getMessage());
                  continue;
              }
              //Used to terminate loop when both first &amp; last names are valid
              validName = true;
          }
  
  
      }
  }
  </code></pre>
  
  <p>I want to make the program repeat the error message when the user inputs a blank name instead of restarting the entire program from the beginning. </p>
  
  <p>E.g When the user enters a blank first name, i want the program to keep repeating "Please enter a first name of at least 1 character" and when the user enters a blank last name, for it to keep repeating "Please enter a last name of at least 1 character" until the user enters a valid name.</p>
  
  <p>However, currently when the user enters a blank first name or last name, my program will repeat itself from the very beginning instead of repeating just the error message.</p>
  
  <p><strong>How would i go about making the program repeat just the error message?</strong></p>