TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: PAUL WANKADIA
from: THOMAS MAEDER
date: 1997-04-16 19:55:00
subject: self-destruct

PW> Well, tell me everything I need to know ... and then some.
class ShouldIReally
{ 
    public: 
        class NoIShouldnt
        {
            // intentionally empty
        };
        ShouldIReally() 
        { 
            if (yes()) 
                okLetsDoIt(); 
            else 
                throw NoIShouldnt();
        } 
};
int main() 
{
    try
    {
        ShouldIReally s;
        // if you arrive at this line, s is fully constructed
    }
    catch (ShouldIReally::NoIShouldnt &)
    {
        // if you arrive at this line, s threw an exception
    }
}
Above the most simple sample code that came to my mind.
If  the  constructor  called the base class constructor or constructed
some member variables before throwing the exception,  the  constructed
(sub)objects  will  be  destructed before the constructor is left; but
the SouldIReally destructor will not be called since s  is  not  fully
constructed when the exception is thrown.
Thomas
---
 þ MM 1.0 #0113 þ Television is democracy at its ugliest.
---------------
* Origin: McMeier & Son BBS (2:301/138)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.