title: Catching exception and requesting user to re-enter input
body: <p>I'm creating a program that opens and then reads files which users have specified, currently the code I have looks like:</p>
  
  <pre><code>    System.out.println("Enter the name of the file you want to open: ");
      FileN = scan.nextLine();
      // I want the program to return to this point here if an error has occured.
      try
      {
          scan = new Scanner(new File (FileN));
      }
      catch(Exception e)
      {
          System.out.println("Could not find file" + e);
          System.out.println("Please enter a valid file name: ");
  
      }
  </code></pre>
  
  <p>I have specified above where I want the program to return to within the code, I have currently tried creating a loop and then using continue however it wont let me put a try within the loop. Also I've tried to create a new void and it still wont work. Currently the program continues to run even if the user has entered an invalid file name.</p>
  
  <p>I have searched for an answer already and can only find this relating to what I want: <a href="https://stackoverflow.com/questions/29113457/java-exception-handling-how-to-re-enter-invalid-input">Java - Exception handling - How to re-enter invalid input</a></p>
  
  <p>Also clarifying what I mean by putting a try in a loop; yes, it is possible. However I want to know whether for the continue to work in my program, do I put the try inside the loop or the loop inside the try? I have referred to: <a href="https://stackoverflow.com/questions/141560/should-try-catch-go-inside-or-outside-a-loop">Should try...catch go inside or outside a loop?</a> </p>
  
  <p><a href="https://i.stack.imgur.com/hJOTE.jpg" rel="nofollow noreferrer">This is the error I'm currently getting with my latest code</a></p>