Custom Error Message

I am trying to have my error message read "Uninitialized variable NameOfVariable", how can I add the variable (such as x or y...underlined in the code below) to my message, I need to pick it up from where my exception is thrown, which is in a different class than where it is caught.

Thanks in advance.
____________________________________________________________________________

class NonInitialized : public runtime_error
{
public:
NonInitialized::NonInitialized() : runtime_error( "Uninitialized variable" ) {}
};

----------------------------------------------------------------------------
Exception thrown here:
for (int i = 0; i < elements.size(); i++)
if (elements[i].variable == variable)
{
return elements[i].value;
} else {
throw NonInitialized();
}
Last edited on
Topic archived. No new replies allowed.