title: Retry the try block in try-catch in java
body: <p>I am new to java and have the following question. I have found a couple of answers on this but still am not clear how to implement the <strong>while block</strong> to solve the problem:</p>
  
  <p>In the below code, I am trying to receive info about 'product name' and 'price' from the user input. product name is a string retrieved using the scanner.next() function and price is a double. If user gives product name incorrectly like with using a space, an error is thrown by scanner class which I catch in the catch block. 
  Question is how can I go back to the try block and give the user a second chance at inputting the product name value instead of exiting from the system? I did a lot of search on this problem but still haven't found a solution.</p>
  
  <pre><code>String[] sArrProdName = new String[newUser.getNumberOfItemsInStock()] ;
      double[] sArrPrice = new double[newUser.getNumberOfItemsInStock()];
  
      for(int i=0;i&lt;newUser.getNumberOfItemsInStock();i++)
      {
          try {
  
          System.out.println("Enter product Name: ");
          sArrProdName[i]= s.next();
          System.out.println("Price? : ");
          sArrPrice[i] = s.nextDouble();
  
          }
          catch (InputMismatchException e) {
  
              prompt("Enter product name correctly");
  
          }
      }   
  </code></pre>