Menu

#27 Exception's what() return invalid pointer.

open
nobody
Common (1)
5
2008-04-10
2008-04-10
No

Exceptions do all return an invalid pointer to a temporary object in their what() method.

Example:

const char* PacketErrorException::what() const throw()
{
string str = "PacketErrorException: " + my_reason;
return (const char*)str.c_str();
}

Possible solution:

Construct the message string already in the constructors, the return value lives as long as the exception.

Discussion


Log in to post a comment.