Menu

Constructors throw exceptions

2000-01-19
2000-01-19
  • Daniel Silverstone

    This is sound in the short term, however, you need to consider the possibility that users may want smart pointers. This can cause problems when things are "delete"'ed.

    Are you considering smart pointers (garbage collection) or not - if not, why not, and if so - have you considered the problems involved?

    (Not wanting to sound bad - just promoting discussion)

     
    • Frank V. Castellucci

      Help me understand how SmartPointers cause problems with invarient state exceptions?

      Yes, we have SmartPointers as a requirement, we will be providing them, and have used them for a long time in past lives <g>.

      I appreciate the discussion. Some of which leads to the fine points on defining the requirement details.

       
      • Daniel Silverstone

        The problem we had and good design I suppose will circumvent this, was as follows...

        AgentHandle is a smart reference counter for Agents, and AgentManager did Agent* = new Agent() and then added it to a handle.

        where constructors could throw exceptions, we had problems with lines like

        AgentHandle i = AgentManager::NewAgent();

        Here if the constructor threw, we ended up with agents which had never been cleaned up destroying themselves, leaving trailing pointers, and other problems.

        Basically - this was a Caveat - if you are allowing constructors to throw exceptions - make sure they cleanup first. Not all compilers are as Ansi compliant as the latest G++

         

Log in to post a comment.

MongoDB Logo MongoDB