Originally posted by vicodin451
One idea:
Code:
CYourClass::CYourClass
{
if( !Init() )
{
CWhateverExceptionYouWant TheEx;
// Set up TheEx
throw TheEx;
}
}
I don't understand this part is this the client?
Code:
try
{
CYourClass Yadda;
UseYadda( Yadda );
}
catch( CWhateverExceptionYouWant& rTheEx )
{
// Use rTheEx...
}
Code:
void UseYadda( CYourClass& rYadda )
{
// ...
}
Personally, I avoid throwing exceptions from constructors whenever possible (usually always). As you can see, it is kind of a pain. If you do decide that your constructor should throw, you should make it
very well known that it can throw an exception.
How many classes do you know of, where the constructor throws an exception?