D
** TRY , CATCH und END_CATCH sind Präprozessor-Macros, die von MFC definiert werden und die letztendlich auch bloß das normale C++ try...catch verwenden. CException **ist die Basis-Klasse, von der alle MFC-spezifischen Exceptions abgeleitet sind.
Der Unterschied ist, dass** TRY...CATCH...END_CATCH ausschließlich mit Exceptions funktioniert, die vom Typ CException* sind bzw. die von diesem Typ abgeleitet wurden. Also mit Excpetions vom Typ int **klappt es schon mal nicht, wie Du ja bereits gemerkt hast
Das normale** try...catch Funktioniert hingegen mit beliebigen Exceptions. Der einzige "Vorteil" von TRY...CATCH besteht darin, dass das CException -Objekt beim Verlassen des CATCH...END_CATCH **Blocks "automatisch" zerstört wird.
Natürlich könntest Du Exceptions des Typs** CException* auch mit dem ganz normalen try...catch anstatt TRY...CATCH abfangen. Nur müsstest Du dann halt das Exception-Objekt explizit mittels Delete() **zerstören - ansonsten handelst Du Dir ein Memory Leak ein!
#define TRY { AFX_EXCEPTION_LINK _afxExceptionLink; try {
#define CATCH(class, e) } catch (class* e) \
{ ASSERT(e->IsKindOf(RUNTIME_CLASS(class))); \
_afxExceptionLink.m_pException = e;
#define AND_CATCH(class, e) } catch (class* e) \
{ ASSERT(e->IsKindOf(RUNTIME_CLASS(class))); \
_afxExceptionLink.m_pException = e;
#define END_CATCH } }
The major difference between the macros and the keywords is that code using the macros "automatically" deletes a caught exception when the exception goes out of scope. Code using the keywords does not, so you must explicitly delete a caught exception. The C++ exception-handling keywords are more versatile: They can handle exceptions of any data type that can be copied (int, float, char, and so on), whereas the macros handle exceptions only of class CException and classes derived from it.
Zusammengefasst:
Wenn Du es mit Exceptions des Typs** CException* zu tun hast, kannst Du TRY...CATCH...END_CATCH benutzen, auch wenn das kein Muss ist. In allen anderen Fällen musst Du ohnehin direkt mit try...catch **arbeiten.
Siehe dazu auch die beiden Beispiele auf der offiziellen MSDN Seite, da ist eigentlich alles ausführlich erklärt:
http://msdn.microsoft.com/en-us/library/19z28s5c.aspx