Flow Control with Exception Handling
I'm using exception handling to catch errors, but cannot figure out how to prevent the code after the exception from executing. Example:
try
Statement 1
catch
Error handling for Statement 1
Statement 2
Statement 3
If there is an error with Statement 1 (in this case a null value in a text box), I don't want Statements 2 & 3 to execute since they rely on a valid value. Also Statements 2 & 3 deserve their own try...catch statements. So, I am left with a hugely nested set of try...catches to handle flow control.
I know this is not correct. How should I handle it?
Thanks,
Scott
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Manoj Kumar2 pointsPosted May 17, 2007, 9:45 AM EDT
chirag patel2 pointsPosted May 17, 2007, 11:26 AM EDT
try{
sttement1;
}
catch
{
statement2;
}
statement3;
statement4;
u can do:
int c = 0;
try{
sttement1;
}
catch
{
statement2;
c++;
}
if(c!=0)
{
statement3;
statement4;
}
i think this will solve u r problem.
letme know
regards
chirag