How to avoid goto in this code

Hi,
How can avoid using goto in this code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int f(){} // may or may not throw an exception

int main()
{

int x;

try
  {
      x=f();
  }
catch(int &ex)
  {
      if(ex==666)
          goto skip;
      // if ex!=666 continue execution below catch{} block
  }

// code

skip:

// more code


    
}

If f() throws 666, I want to skip a block of code under catch(...). Is this possible without using goto?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int f(){} // may or may not throw an exception

int main()
{
    int x;
    try
    {
        x = f();
        // code
    }
    catch(int &ex)
    {
        if (ex != 666)
        {
            // do your exception handling ...
        }
    }

    // more code
}
I knew that solution must be simple... Thanks for help!
You must be sure that // code doesn't throw int or the two code fragments above won't be equivalent
This problem can be fixed with another try-catch block:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int f(){} // may or may not throw an exception

int main()
{
    int x;
    try
    {
        x = f();
        try 
          {
             // code 
          }
        catch(...)
         {
             
         }
        
    }
    catch(int &ex)
    {
        if (ex != 666)
        {
            // exception handling ...
        }
    }

    // more code
}
Topic archived. No new replies allowed.