Re: Exception handling?
Hey thanks for replying, this thread picked up while your timezone
was sleeping. I will respond to this one first and then any other
replies you sent to me if not material already covered here.
As I said: you are not permitted to write try/catch statements ;-)
Yes I do remember you saying that but at the time I did not really
understand what you meant by it other than the fact that most of the
time it would end up being counterproductive or something to that
effect. I get the most from your replies after I experiment thru a
few foobar attempts and then go back and read them again.
I also remember you saying,
Find the answer to that, and you'll find that you don't need a try/catch
And I have found the answer to that.
But on your code example,
try
{
workworkwork();
}
catch(CException* p)
{
DEL_ON_EXIT(p);
p->ReportError();
}
I see what calling ReportError does. When I tried it in my code
it just called reported the error but did no cleanup etc, so obviously
you were obviously explaining " in relation to " here.
However I would like to express these couple of items here
since I am learning LOADS from all of this.
First off exactly what is the define DEL_ON_EXIT ? My VC6
compiler doesn't reconize it so I need the include or whatever ?
Second when I ran this,
catch (CException* e)
{
// do Whatever
e->ReportError( ); runs reports and returns
throw; // pass it on framework handlers
// The throw gives me all of what ReportError did and more,
// including a DELETE_EXCEPTION(e);
// so I surmize this is some of what you meant when you said
// I should not be using try and catch .
}
In this case (wrong "magic" in the file), you have these options
(AFAICanSee):
1. use AfxThrowArchiveException with e.g. badIndex (kinda silly name
given the associated message, but fair enough).
Yes I had stumbled along until I came up with this,
// in my doc serial load loop
ar >> FID_Read;;
if (FID_Read != FileID)
{ // FileID mismatch
AfxThrowArchiveException(CArchiveException::badIndex, NULL );
}
......
This thread took off with so many opinions on try and catch that I lost
track at first. But in summation I learned the syntax I was after and LOADS
of concept. I feel a more confident level dummy 1.0 now