title: Asking for input after catching an exception
body: <p>I want the user to enter a number which is scanned by the following code:</p>
  
  <pre><code>scanner.nextInt();
  </code></pre>
  
  <p>If a user enters a string instead, the program throws <code>InputMismatchException</code>, which is obvious. I want to catch the exception in such a way that the program prompts the user to enter an input until the user enters an integer value.</p>
  
  <pre><code>Scanner scanner = new Scanner(System.in);
  while(true) {
      try {
          System.out.println("Please enter a number: ");
          int input = scanner.nextInt();
          System.out.println(input);
          //statements
          break;
      }
      catch(InputMismatchException | NumberFormatException ex ) {
          continue;
      }
  }
  </code></pre>
  
  <p>This code creates an infinite loop if a string is entered.</p>