Exception handling within a for loop
807598May 23 2006 — edited May 23 2006Hi there,
Is it possible to have a try...catch block inside a for loop, then using the variable in an instance later?
This is what i'm planning to do and have not been succesful:
for(initial,condition,increment)
{
boolean valid = false;
while (!valid)
{
try
{
variable = Integer.parseInt(stdin.readLine());
valid = true;
}
catch (NumberFormatException e)
{
System.out.println("Not an integer");
}
}
}
array[i] = new newClass(variable);
//end of code
i have been getting 'unreported exception java.IOException; must be caught or declared to be thrown' error messages
Thanks for any help!