Reputation: 9172
I've been using c++ for a while, and I'm familiar with normal try/catch. However, I now find myself on Windows, coding in VisualStudio for COM development. Several parts of the code use things like:
TRY {
... do stuff
} CATCH_ALL(e) {
... issue a warning
}
END_CATCH_ALL;
What's the point of these macros? What benefit do they offer over the built-in try/catch?
I've tried googling this, but "try vs TRY" is hard to search for.
Upvotes: 8
Views: 6490
Reputation: 41718
The macros were important for use with an earlier version of the compiler. They are still supported for compatibility with legacy code, but otherwise are not recommended for use.
The documentation for Exception Handling in Visual C++ says this about MFC exceptions:
Since version 3.0, MFC has used C++ exceptions but still supports its older exception handling macros, which are similar to C++ exceptions in form. Although these macros are not recommended for new programming, they are still supported for backward compatibility. In programs that already use the macros, you can freely use C++ exceptions as well. During preprocessing, the macros evaluate to the exception handling keywords defined in the Visual C++ implementation of the C++ language as of Visual C++ version 2.0. You can leave existing exception macros in place while you begin to use C++ exceptions.
Upvotes: 0
Reputation: 2266
You'll want to keep in mind that there are 3 different kinds of exceptions when programming with Visual C++:
SEH and C++ exception mechanisms should not be mixed.
This article on MSDN has more details:
http://msdn.microsoft.com/en-us/library/x057540h.aspx
Upvotes: 3
Reputation: 12359
It's an artifact of Windows programming from before the days when try/catch wasn't well supported by compilers, or wasn't supported at all.
Upvotes: 1
Reputation: 86116
It's an MFC macro:
http://msdn.microsoft.com/en-us/library/t8dwzac0%28VS.71%29.aspx
This page says they're a remnant from MFC 1.0 - use normal C++ exceptions in new code:
MFC versions lower than 3.0 did not support the C++ exception mechanism. MFC provided macros to deal with exceptions.
Upvotes: 8