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)
|