From: bouncer@dev.null   
      
   Dave Abrahams wrote:   
      
   > on Tue Jun 05 2012, Wil Evers wrote:   
   >   
   >> Dave Abrahams wrote:   
   >>   
   >>> So in your view, there is a substantial difference between:   
   >>>   
   >>> struct C { C(){throw 1;} };   
   >>> void f()   
   >>> {   
   >>> C x;   
   >>> ...   
   >>> }   
   >>>   
   >>> and   
   >>>   
   >>> struct D { ~D(){throw 1;} };   
   >>> void f()   
   >>> {   
   >>> {D x;}   
   >>> ...   
   >>> }   
   >>>   
   >>> in terms of their meaningfulness or handle-ability? I'd be   
   >>> interested in your explanation, if so. It seems to me that as the   
   >>> user of f(), I don't care whether the exception came from C's   
   >>> constructor or D's destructor.   
   >>   
   >> In C++11, in the first example, an exception will escape from f(),   
   >> while in the second example, the terminate handler gets called. To   
   >> me, that sounds like a pretty substantial difference.   
   >   
   > I think you are mistaken. Both programs have the same behavior.   
      
   As far as I know, in C++11, destructors are noexcept by default, so D is   
   equivalent to   
      
    struct D { ~D() noexcept { throw 1; } };   
      
   The 'throw 1;' breaks the promise not to throw; hence the call to the   
   terminate handler.   
      
   Regards,   
      
   - Wil   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|