Re: throwing CException

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Is this OK:
> try {
> callSomeFunc();
> } catch (CException &e) {
> char msg[999];
> e.GetErrorMessage(msg, sizeof(msg));
> AfxMessageBox(msg);
> return;
> }
No.

> or I _have_ to use "CException *e"?
When you used the throw statement you used the new statement to create an
instance of the class on the heap, which returned a pointer to that
instance; and that pointer was "associated" with the exception... So
catching the exception sould match the associated data (in your case the
pointer to CMyException, or its parent for that matter)

> Also, do I have to call e->Delete() and when?
As I said you created the class instance on the heap, so you HAVE to delete
it (Unless you want to see some memory leaks), and of course the deletion of
a pointer (allocated on the heap) should happen when you're done with it,
apparently :)


Abdo Haji-Ali
Programmer
In|Framez


.


Quantcast