Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Infinite loop in a catch {} statement, should be simple

807603Jan 30 2008 — edited Jan 30 2008
Hi, 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 :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 27 2008
Added on Jan 30 2008
6 comments
344 views