views:

87

answers:

3

One of my programs crashes periodically, but I don't know why. I'm running it in debug mode, but nothing pops up. The program just suddenly exits. I've had other bugs that do throw an exception...but not this one. Is there a magical way of catching it or something?

+4  A: 

Presumably you're running it from within Visual Studio and for some reason it's not stopping in the debugger with an uncaught exception, in which case you could try catching the crash from outside of Visual Studio. See my answer at http://stackoverflow.com/questions/3652380/system-accessviolationexception-from-unmanaged-code/3655392#3655392, in particular how to capture a crash dump.

If it only crashes periodically, but within a reasonably short period of time, start with Sysinternals procdump. Start your executable from outside Visual Studio, then run:

procdump -e <YourExecutableNameOrPid>

and wait for it to harvest a crash dump - assuming it exits due to an unhandled exception - then load the crash dump into VS 2010 or WinDbg.

Sean Fausett
+3  A: 

The program just suddenly exits

definitely check that your code, or one of the libs you use, does not call exit() (yeah might sound too simple, but we once lost hours tracing random programs shutdowns back to exit() calls..). If so, put a breakpoint there or change to throw(), then run again. If not, Sean's answer seems legit.

stijn
We had this exact problem once and it took us ages to figure out. It's worth checking for.
Cosmic Flame
Also you should set a breakpoint or some log statement as last line in main() / winmain(). Possibly the program terminates "normally" thereby in a unexpected way.
RED SOFT ADAIR
@Red: It's a WPF GUI app... all the code is in events, I don't think it should ever reach the end. @stijn: Pretty sure I didn't write any exit calls, but I'll double check.
Mark
A: 

You can find more suggestions at the following similar post: Third-party dll crashes program with no exception thrown.

Sergey Vlasov