Java Try-catch block, Catch block does not re-prompt the user for a new value
<p>I am new to Java and would like to ask you a question.</p>

<p>I have written the below code where "<code>numOfThreads</code>" should be assigned a valid int value by the user through the Console.</p>

<p>However, I would like to achieve a result where if the input is incorrect and we go in the catch block, the user should be re-prompted to enter "<code>numOfThreads</code>" until it is of correct type and range.</p>

<p>For some reason I seem to go into infinite loop. Can you please assist? Thanks :)</p>

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

public class Main {

    public static void main(String args[]){

        int numOfThreads;
        boolean promptUser = true;

        Scanner keyboard = new Scanner(System.in);

        while (promptUser)
        {
            try{
                numOfThreads = keyboard.nextInt();
                promptUser = false;
            }
            catch(Exception e){
                System.out.println("Entry is not correct and the following exception is returned: " + e);
                numOfThreads = keyboard.nextInt(); // DOES NOT SEEM TO BE ASKING FOR A NEW INPUT
            }
        }
    }
}
</code></pre>