Infinite loop in a catch {} statement, should be simple
807603Jan 30 2008 — edited Jan 30 2008Hi, I'm trying to take integer input from the console using a Java Scanner object, and I enter an infinite loop if there is an IO error inside the catch statement. Please let me know if you know what I'm doing wrong:
do
{
try
{
Problem = false; //this is a bool
start = Input.nextInt(); // Input is a Scanner, start is an Intenger
}
catch (Exception IOException) {
Problem = true;
System.out.println("Bad value.\n");
//The infinite loop is inside this statement.
}
}
while (Problem == true);
This code block is intended to take integer input, then, if there's an IO error, try to do it again, indefinitely, until it has successfully given Start a value. As it stands, if executed, if there is not an IO error, it works; if there is an IO error it enters an infinite loop in the catch statement. Please forgive my incompetence, any help is appreciated :)