Skip to content
Johan Wikman edited this page Apr 19, 2017 · 17 revisions

From 2.2 onwards MaxScale will be built as C++. That does not mean that MaxScale will be rewritten in C++ but that C++ can be used were appropriate.

General Rules

MaxScale code must not throw exceptions.

The corollary of that is that the reserving of some resources can fail, then it cannot be done in the constructor. In practice that means that if the creation of an object may fail, then there must be a separate create-function that reserves the resources and once reserved, creates the object or returns NULL if the creation fails.

class Heavy
{
public:
    static Heavy* create(...)
    {
       Heavy* pThis = NULL;
       auto_ptr<Resource>*sResource(...);
       if (sResource.get())
       {
           pThis = new Heavy(sResource);
       }

       return pThis;
    }

private:
    Heavy(auto_ptr<Resource> sResource)
        : m_sResource(sResource)
    {
    }
};

Note that although MaxScale code itself must not throw exceptions, the runtime-library may do so (e.g. new if the allocation fails).

MaxScale C++ code should be exception safe

Even though MaxScale code itself must not throw exceptions, new C++ code should be exception safe. That is,

Clone this wiki locally