Hi,

if I would like to inherit runtme_error exception class I could write lite this:

class MyOwnException : public runtime_error
{
        public:
                MyOwnException(const char *msg);
                
};

MyOwnException::MyOwnException(const char *msg) : runtime_error(msg)
{

}

But what if I would like to have another datatype in the constructor
like an int instead of the char *msg, and to compose my own message
and pass that to the runtime_error constructor.

For example, I would like to create a InvalidIndex exception:

class InvalidIndexException : public runtime_error
{
        public:
                InvalidIndexException(int index);
                
};

InvalidIndexException::InvalidIndexException(int index) :
runtime_error(format("Invalid index %d", index))
{

}

Wouldn't that lead to a memory leak, since the new char buffer from
the format function is dever deleted?

One other question, is it possible to not declare which base
constructor to call in the method header
"MyOwnException::MyOwnException(const char *msg) : runtime_error(msg) "

but call the base contructor on my own in the method body?

//John

Reply via email to