I have a function with a try catch block that looks like this:
bool apple()
{
OutputDebugStringW(L"entered apple");
try {
SomeObj orange;
int a = global_b->num; // global_b is NULL
int b = global_b->someothernum; // global_b is NULL
}
catch(...) {
OutputDebugStringW(L"leaving apple due to exception");
return false;
}
OutputDebugStringW(L"leaving apple normally.");
return true;
}
A single time in DbgView I saw this:
entered apple
leaving apple due to exception
leaving apple due to exception
The function is called on DllMain PROCESS_ATTACH. What's happening? Unfortunately I recompiled the code, and when I changed it back to the way it was in an attempt to reproduce the exception message appearing twice I couldn't.
This is in Visual Studio 2010 SP1 using DbgView 4.79. Has anyone ever seen something they output using OutputDebugString output twice?
Edit- Thanks to those who answered this. The answers point out that I cannot rely on a NULL pointer exception. In Visual Studio I use /EHa
to catch everything as a C++ exception so that if there's any problem with any function I'm wrapping that I can just abort due to exception. Is it ok if I used /EHa
to expect that access violations will be passed to catch(...)
? I thought so.