I have a mysterious crash that I'm struggling to locate in a large multi-threaded application compiled in MSVC 2005. The application is in daily use by a client, and any crashes cause significant disruption to them. I need a workaround. If I could isolate the issue to one function, and do something along these lines:
__try
{
FunctionWhichMayCauseCrash();
}
__except ( [filter expression] )
{
Recover(); // magic - this allows us to prevent crash and continue
}
then that would seem like a good idea to me in theory. In practice, some people (e.g. Larry Osterman here and Doug Harrison here) make it sound like it might be a very bad idea - that SEH should not be touched with a barge pole.
Reality check: my program is generating structured exceptions, and I know not where. I am using parts of Hans Dietrich's XCrashReport - which itself uses __try/__except
- to try to get insights into the source of these exceptions, but with no luck so far. It seems likely that some shared resource is not being properly locked, so that one thread is pulling the rug from beneath another thread, causing an access violation in a more or less random place.
Is there a pragmatic middle ground where such a mechanism could prevent my program from crashing? Should I be concerned that my crash recovery mechanism of choice uses something that others are wary of?
Clarification: because of the extreme disruption caused by program crashes, I seek a workaround that prevents crashes, NOT a final permanent solution. I have no intention of using __try/__except
to sweep an issue under the carpet. I am merely trying to understand whether it is as dangerous as some people make it sound, or a legitimate tool that should be used with care. The way some people talk, the very moment I try compiling my code with /EHa
defined, my computer will probably burst into flames. I am interested to know whether people would say using /EHa
, _set_se_translator
and try/catch(...)
is better, or amounts to the same thing, or whether both are really bad ideas.
Clarification 2: I don't need help debugging :-) Rather, I need help understanding the implications of mixing SEH and C++, something which seems to generate more heat than light on this and other forums. My low reputation indicates newness to forum, not newness to C++. I deliberately abstracted my application out of the question to encourage people to focus on the implications of introducing SEH constructs to a C++ program. Well that didn't work :-) As it happens, my application has a pipeline of objects any of which I can readily dump if I detect corruption in them. So my magical Recover()
function is not nearly as magical as it might sound, and there is a good chance that corruption will be limited to a small part of the heap. So... back to the question: is using __try/__except
advisable?