Original Post
Just boning up on my C++, and as such am relearning exceptions (after being muddled up by Java's...). Two quick questions(I haven't actually tried #1, but just because it works, doesn't make it right, so the question still stands): 1. Is there any reason this is bad? (assuming TException is a defined class that takes std::string as a constructor param, etc) 2. If a function does throw, what should the functions return type be? Currently all my functions return a TRESULT which is just a typedef'd unsigned int. So T_OK is 0x1 etc. Then I am just testing for all these return codes. UGLY. Right, so should I keep the return values and just throw when bad things happen or should I change them into voids? or any guidance would be much appreciated
void foo()
{
if(!bar())
throw( new TException("Error has occured"));
}
void bar()
{
try
{
foo();
}
catch(TException &e)
{
cout << e.getString() << endl;
}
}
TRESULT foo()
{
if(! blah)
throw(new TException("error"));
return T_OK;
}
void foo()
{
if(! blah)
throw(new TException("error"));
}