Re: try...catch vs TRY...CATCH
"David Wilkinson" <no-reply@effisols.com> wrote:
What does deleting the CException pointer have to do with
whether you use try/catch or TRY/CATCH?
If I use try/catch, then usually exceptions are thrown by
value and handled by reference. I.e., I don't need to
perform any special clean up for exception object. MFC
throws pointer to object, allocated with `new' and obligates
me to call e->Delete() in exception handler code. Now I have
two options:
1. To use try/catch, therefore
+ code looks more conforming C++ standard
+ my exceptions can be thrown as I wish
- MFC exceptions must be caught by pointer to CException
(or derivative)
- MFC exception must be deleted in catch block
- my exceptions require separate catch clause, or..
- my exceptions are derived from CException and play by
MFC rules
2. To use TRY/CATCH, therefore
- code looks less conforming C++ standard
- my exceptions derived from CException and play by MFC
rules
+ not necessary to delete both MFC and my exceptions
+ not necessary to separate catch clauses for MFC and my
exceptions
+ my exception will require GetErrorMessage or similar
method anyway, so why not to derive it from CException (or
other MFC exception) all the time.
Considering all this I find using TRY/CATCH approach being
more consistent and less error prone.