At 16:16 2007-03-09, John Gunnarsson wrote:
>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))
>{
>
>}

looks good to me except for your undefined "format" function..and why 
do you seem to like the "printf" metaphor

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

what "new char buffer" ?


>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?

what's wrong with calling a function from the initializer list?  and 
btw, runtime_error takes a std::string const& as it's argument for 
its constructor, it definitely does NOT keep a pointer to a char* internally


>//John
>
>
>
>To unsubscribe, send a blank message to 
><mailto:[EMAIL PROTECTED]>.
>Yahoo! Groups Links
>
>
>

Victor A. Wagner Jr.      http://rudbek.com
The five most dangerous words in the English language:
               "There oughta be a law" 

Reply via email to