   Error Handling
  Hi,I'm wondering if anyone can suggest any mechanisms for handling fatal errors. I have found the following posts here and here but now I'm confused... information overload :(My engine class looks pretty much like thisclass cEngine{public:    cEngine(...);    ~cEngine();    cInput   *GetInput();    cRenderer*GetRenderer();    // etcprivate:    cInput   *m_input;    cRenderer*m_renderer;    // etc...};Each system (e.g. input) is initialized in the engine ctor and sets an internal flag to show if it was loaded correctly or not, and the engine checks this like so:cEngine::cEngine {    m_loaded = false;    m_input = new cInput(...);    if( !m_input->IsLoaded() )   return;    // etc...    m_loaded = true;}This seems really bad, there is no way to tell which objects in m_input were initialized, and so either they are leaked or the program crashes when the destructor tries to delete/release them.Additionally, using flags isn't very C++ish, and checking the loaded flag for almost every method (especially in cRenderer::DrawFrame, etc...) seems bloated and will kill speed.Can anyone suggest another method? I've looked into throwing exceptions in the ctors, and catching them in the engine ctor, but that still leaves the problem of leaked memory...Many thanks if anyone can help :-)   
  If you absolutely can't carry on without a renderer or an input'er, why not throw an exception that can be handled by the code that attempts to instantiate CEngine. If it catches an exception they can log it to a file and exit gracefully.Dave   ;RAII is C++'s method of ensuring that resources are dealt with appropriately, even in the presence of exceptions.  In this case specifically, you'd want to look at smart pointers.  I think in this case, std::auto_ptr or boost::scoped_ptr would work.  The moment you create an object with new, you store it in a smart pointer (probably using that smart pointer's constructor).  Then, if the object ever gets destructed, the smart pointer will take the appropriate action on it's internal raw pointer.  If the pointer is NULL, however, nothing happens.  So you're safe whether you've initialized that pointer or not.   ;  use exception you can track many information than just a flag can do.and use flag to indicate whether a exception has been thrown, this may cause problem while you are in multithread.   