Hi,
Well i was really tired when I wrote that email, confusing functions between
different languages.
But let me rephrase myself:
How would I declare a exceptionclass called InvalidIndexException which
takes an int as a argument in the constructor,
the constructor will then call runtime_error's constructor with the string
"Invalid index: X" where x is the int
passed in the new constructor declared in InvalidIndexException?
//John
On 09 Mar 2007 21:46:52 -0800, Victor A. Wagner Jr. <[EMAIL PROTECTED]>
wrote:
>
> 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]<c-prog-unsubscribe%40yahoogroups.com>
> >.
> >Yahoo! Groups Links
> >
> >
> >
>
> Victor A. Wagner Jr. http://rudbek.com
> The five most dangerous words in the English language:
> "There oughta be a law"
>
>
>
[Non-text portions of this message have been removed]