stock unwinding from GotW #47

Discussion in 'C++' started by puzzlecracker, May 1, 2008.

  1. It is per Sutter's GotW #47 article. I don't understand why if a U
    object is destroyed due to stack unwinding during to exception
    propagation, T::~T will fail to use the "code that could throw" path
    even though it safely could.

    Code from the article:

    // The wrong solution
    //
    T::~T() {
    if( !std::uncaught_exception() ) {
    // ... code that could throw ...
    } else {
    // ... code that won't throw ...
    }
    }


    // Why the wrong solution is wrong
    //
    U::~U() {
    try {
    T t;
    // do work
    } catch( ... ) {
    // clean up
    }
    }
    puzzlecracker, May 1, 2008
    #1
    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. savvy
    Replies:
    1
    Views:
    475
    Cowboy \(Gregory A. Beamer\)
    Jun 28, 2006
  2. Srini
    Replies:
    5
    Views:
    292
    Herb Sutter
    Sep 10, 2005
  3. George2

    Challenging GotW 66's moral

    George2, Dec 27, 2007, in forum: C++
    Replies:
    4
    Views:
    392
    Salt_Peter
    Dec 27, 2007
  4. Niels Dekker - no return address

    GotW #88: Is it safe to const_cast a reference to a temporary?

    Niels Dekker - no return address, Feb 2, 2008, in forum: C++
    Replies:
    17
    Views:
    884
    Niels Dekker - no return address
    Feb 6, 2008
  5. parvathi
    Replies:
    0
    Views:
    427
    parvathi
    Feb 3, 2009
Loading...

Share This Page