Skip to Main Content

New to Java

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!

Exception handling within a for loop

807598May 23 2006 — edited May 23 2006
Hi 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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 20 2006
Added on May 23 2006
3 comments
94 views