Re: CORRECTION Re: confused by exception handling in VC 2008
"Alan Carre" <alan@twilightgames.com> wrote in message
news:OM8dF9mXJHA.5272@TK2MSFTNGP04.phx.gbl...
My understanding is what did Not Play Well Together was compiling with
/EHa and using try (without the double underbars) to handle both Win32
and C++ exceptions.
As above, yes. It is not recommended to use SEH blocks directly when
compiling with /EHa. Instead use a translator to convert all SEH
exceptions to C++ exceptions as described in the MSDN help under "Mixing
C (Structured) and C++ Exceptions".
Sorry, bad wording from me... This is what I meant to say:
Yes you will run into problems as you mentioned using try/catch, and you
don't want to start writing __try/__catch in your C++ code. Which means
that you need a way to *silence* asynchronous exceptions under /EHa, and
turn them into synchronous C++ exceptions. The translator function, if
implemented correctly, does exactly that. Meaning your regular try/catch
blocks will now work properly even if an async exception occurs: ie. it
will be converted to a C++ exception first, and then thrown and caught as
normal along with everything else. Basically it's as if there were no 'a'
at all and only /EH specified (ie. C++ exception handling only).
Thanks Alan. I had not previously understood that to combine both Win32 and
C++ exceptions, the ideal answer is to compile with /EHa and use
_set_se_translator().
For my purpose, though I think /EHsc + __try/__catch is the best. First, I
am only concerned about catching Win32 exceptions; the rest of my code does
not use C++ exceptions (except for what little MFC uses), and I don't need
to catch both in the same handler. Further, my code is Windows only, so I
don't need to avoid __try/__catch. This allows me to use the faster /EHsc
instead of /EHa.
Actually, I'm not even convinced I need __try/__catch since I use a global
handler set by SetUnhandledExceptionFilter() to handle Win32 exceptions at
the moment.
Cheers,
David