title: How do you catch enter key as an error in java eclipse?
body: <p>this is what i'm trying to do: </p>
  
  <p>User enters numbers into the program and program does stuff with it. </p>
  
  <p>but if the user were to just type the "enter" key (or "return" key) eclipse says   </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0</p>
  </blockquote>
  
  <p>what i need for eclipse to say is "invalid input" and ask for the input again. </p>
  
  <p>This is how i am getting the input: </p>
  
  <p>I am using one buffered reader in one function, and i am calling the function whenever i need to read input from the user. Here are my codes for this function incase you want to refer to it. Also, the program is a coverage optimization program, incase you wanted to know that as well. Thank you so much for your help!</p>
  
  <pre><code>public static String Reader() {
    BufferedReader nerd = new BufferedReader(new InputStreamReader(System.in));
    String rvalue = "0";
    try {
      rvalue = nerd.readLine();
      if(elements_typed == 0) {
        Integer.parseInt(rvalue);
      }
      if(sets_typed == 0) {
        Integer.parseInt(rvalue);
      }
      return rvalue; 
    } catch (IOException e) {
      System.out.print("ERROR: Input must be an integer in [1, infinity]!");
      display_menu();
    } catch (NumberFormatException e) {
      System.out.print("ERROR: Input must be an integer in [1, infinity]!\n\n");  
      if(elements_typed == 0) {
        System.out.print("Enter number of elements (n):\n");
        rvalue = Reader();
      }
      if(sets_typed == 0) {
        System.out.print("Enter number of sets (n):\n");
        rvalue = Reader();
      }
    }
    return rvalue;
  }
  </code></pre>