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 explicitly compiled with -std=c++0x

That is what is available on all platforms officially supported by MaxScale.

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, the code should be written so that even if an exception occurs, all resources are freed appropriately and MaxScale can continue to run. Guard objects should be used for ensuring the release of resources in preference of try-catch blocks.

Exceptions must not be allowed to pass module boundaries.

Under no circumstances must exceptions be allowed to cross module boundaries. That is handled automatically if the templates maxscale::Filter and maxscale::Router are used.

Clone this wiki locally