where does the throw re-try

Discussion in 'C++' started by Gary Wessle, Mar 18, 2007.

  1. Gary Wessle

    Gary Wessle Guest

    Hi

    in the example code below, if function A or B throw, and I deal with
    it by setting flag to 0, does the code re-execute from the start of
    the try line or it resumes from the function that threw and the flag
    has no effect?

    thanks

    for(;;)
    {
    try
    {
    if( flag == 0 )
    {
    x = some_funciton_output( 0 );
    }
    else if( flag == 1 || flag == -1 ) // reverse
    {
    x = some_funciton_output( 3 );
    }

    if( x == 0 )
    {
    function_A_that_throws();
    }
    else
    {
    function_B_that_throws();
    }
    break;
    }
    catch (const someException& sde)
    {
    flag = 0; // could not reverse, then close in the market
    }
    }
    }
    Gary Wessle, Mar 18, 2007
    #1
    1. Advertising

  2. Gary Wessle wrote:
    > Hi
    >
    > in the example code below, if function A or B throw, and I deal with
    > it by setting flag to 0, does the code re-execute from the start of
    > the try line or it resumes from the function that threw and the flag
    > has no effect?
    >
    > thanks
    >
    > for(;;)
    > {
    > try
    > {
    > if( flag == 0 )
    > {
    > x = some_funciton_output( 0 );
    > }
    > else if( flag == 1 || flag == -1 ) // reverse
    > {
    > x = some_funciton_output( 3 );
    > }
    >
    > if( x == 0 )
    > {
    > function_A_that_throws();
    > }
    > else
    > {
    > function_B_that_throws();
    > }
    > break;
    > }
    > catch (const someException& sde)
    > {
    > flag = 0; // could not reverse, then close in the market
    > }
    > }
    > }


    The exception is "caught" at the "catch", flag is set to seto and it
    drops into the for(;;) which loops it back to the try and then takes a
    different path (possibly) through the nested if's.
    Gianni Mariani, Mar 18, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kerri
    Replies:
    2
    Views:
    12,976
    Kevin Spencer
    Oct 27, 2003
  2. Jon Maz
    Replies:
    7
    Views:
    4,254
    Jon Maz
    Oct 25, 2004
  3. Matt
    Replies:
    1
    Views:
    397
    Michael Rauscher
    Jun 12, 2004
  4. Replies:
    15
    Views:
    7,455
    Roedy Green
    Sep 8, 2005
  5. Emanuele D'Arrigo

    To throw or to throw not?

    Emanuele D'Arrigo, Nov 14, 2008, in forum: Python
    Replies:
    6
    Views:
    298
    Emanuele D'Arrigo
    Nov 15, 2008
Loading...

Share This Page