Question: My problem is that I'm writing a program which is supposed to be readable for the future, and the program has a lot of exception cases. So whenever I have to throw an exception, I have to writer over 10 lines to initialize my exception class and append the information from the program to it. For example as follows:

```
MyExceptionClass ex;
ex.setErrorMessage("PIN_CANNOT_GO_IN");
ex.setErrorDetails("The pin is asked to go to the state IN while the depth of the r-coordinate does not support it");
ex.setResolutionMessage("Configure your coordinates-file to move first to the correct position before changing the state of the pin");
ex.VariableList().resize(5);
ex.VariableList()[0].push_back("Pin state: ");
ex.VariableList()[0].push_back(ToString(pin.getPinState()));
ex.VariableList()[1].push_back("Pin target state: ");
ex.VariableList()[1].push_back(ToString(coordinatesData[coordinatesIndex].targetPinState));
ex.VariableList()[2].push_back("Current r Value: ");
ex.VariableList()[2].push_back(ToString(EncoderPosition.r));
ex.VariableList()[3].push_back("Current phi Value: ");
ex.VariableList()[3].push_back(ToString(EncoderPosition.phi));
ex.VariableList()[4].push_back("Current z Value: ");
ex.VariableList()[4].push_back(ToString(EncoderPosition.z));

ex.printLog();
ex.writeLog(exceptionLogFilePath.getValue());

throw ex;

```

So for only 5 variables, I had to write all that...
Is there an efficient way to contain all information from the program (variables at least) and not rewrite all this every time I wanna throw an exception?

Thanks in advance.

Answer: 
You can use Boost Exception to streamline adding arbitrary data to your exception objects, and to augment them with more relevant data as they bubble up the call stack. You won't have to worry about pre-defining everything you might need to store in exceptions, as you can literally store any data as needed to any exception.
Those textual descriptions should be linked to the exception class inherently, rather than written into each instance as runtime data.

Similarly, all that informational data should be members of the exception class, and you can format it for output as text later (perhaps in a member function of the exception class itself).