I have a question regarding the following code snippet that I came across in one of our old 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 called by the value, which means a copy of the text
"this error message
. The catch clause points to a pointer to char as the expected type of exception. Can someone enlighten me why this works? Another issue in this context concerns the memory allocated for the error message. Since the exception type is a pointer to char *, can we assume that the memory for the error message was allocated dynamically on the heap and should be deleted by the user?
Thanks in advance