Skip to content

Flow Control with Exception Handling

Scott

Asked May 17, 2007, 7:38 AM EDT2 answers
Share
LinkedInX
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.

  • 0
    if you send ur code to me ,hope so i can find a way
    0
  • 0
    if u have:
    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
    0