title: Exception handling, catch causes while loop to stop
body: <p>I have a file that I need to read, print out the integers, catch exception and continue with the next integer to display, and so on until there are no more integers.</p>
  
  <p>The file contains: 12 5 sd 67 4 cy</p>
  
  <p>I want it to display:</p>
  
  <p>12<br>
  5<br>
  Input error<br>
  67<br>
  4<br>
  Input error</p>
  
  <p>However, it only gives me 12, 5, followed by input error, and it stops. 
  I've tried putting everything into a while loop and it loops endlessly with the input exception.</p>
  
  <pre><code>public static void readNumbers()
   {
  
      File inputFile = new File ("C:/users/AC/Desktop/input.txt");
       try
       {
           Scanner reader = new Scanner(inputFile);
           while(reader.hasNext())
           {
                  int num = reader.nextInt();
                  System.out.println("Number read: " +num);
              } 
        }
        catch (InputMismatchException e)
        {
                  System.out.println("Input error ");
        }
        catch (FileNotFoundException e2)
        {
            System.out.println("File not found!");
        }    
    }
  
   }
  </code></pre>
  
  <p>What am I missing so that the loop continues reading the next int and so on?</p>