Hello there,
I have a question regarding the following code snippet I came across in one of our older libraries.
try
{
throw "this is an error message";
}
catch( char* error )
{
cout << "an exception occured: " << error << endl;
}
My understanding of the behavior in this case is, that the error message is thrown by value, which means a copy of the text
"this is an error message"
is thrown. The catch clause specifies a pointer to char as expected type of exception. Can some enlighten me, why this works? Another question in this context concerns the memory allocated for the error message. Since the exception type is pointer to char* one could assume, that the memory for the error message has been allocated dynamically on the heap and has to be deleted by the user?
Thanks in advance