Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exception difficulties 1

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
Hallo. I seem to be having trouble with exceptions. For instance, the following code:

string str="PARAM_1:15";
try{
int assig=str.find('=',0);
if(assig==string::npos)throw("Cannot find equals sign.");
}
catch(const char* msg){
ShowMessage(msg);
}

I am obviously wrong in expecting this snippet to produce the message "Cannot find equals sign.", but I have no idea why.
The execution of the code falls over on the fourth line with the message "raised exception class char * with message 'Exception Object Address:0x11A68AA'."
Changing the catch parameter to a char* instead of const char* hasn't fixed it.
I'm obviously missing a very basic point, but have no idea where to look.
Can anyone offer any insight?

All help gratefully recieved,
Douglas JL

Common sense is what tells you the world is flat.
 
Gday Douglas,

The help stuff on exceptions mentions an exception object reference being passed to the handler. Try (pardon the pun) the following:

string str="PARAM_1:15";
try{
int assig=str.find('=',0);
if(assig==string::npos)
{
Exception *e = new Exception("Cannot find equal sign");
throw(e);
}
}
catch(Exception *e){
ShowMessage(e->Message);
}
 
Thanks alot, man - I'll give that a bash.

DJL

Common sense is what tells you the world is flat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top