[Infinite Loop]Try.. catch with exceptions
<p>So, I`m getting stuck with a method about Scanner, here is the code:</p>

<pre><code>import java.util.InputMismatchException;
import java.util.Scanner;

public class ConsoleReader {

    Scanner reader;

    public ConsoleReader() {
        reader = new Scanner(System.in);
        //reader.useDelimiter(System.getProperty("line.separator"));
    }

    public int readInt(String msg) {
        int num = 0;
        boolean loop = true;

        while (loop) {
            try {
                System.out.println(msg);
                num = reader.nextInt();

                loop = false;
            } catch (InputMismatchException e) {
                System.out.println("Invalid value!");

            } 
        }
        return num;
    }

}
</code></pre>

<p>When I try to input a number(int), everything goes fine, but when I insert something that isnt an int, the exception goes to catch, do the while loop again, go to the try, read the first System.out but don't read the "num = reader.nextInt()" and throw again the exception, going to the catch and doing a INFINITE LOOP.</p>

<p>if the "msg" is "Insert a integer number:", the output is:</p>

<blockquote>
  <p>Insert a integer number:</p>
  
  <p>Invalid value!</p>
  
  <p>Insert a integer number:</p>
  
  <p>Invalid value!</p>
  
  <p>...</p>
</blockquote>
