How to debug a program when it crashes w/out exception?

13,698

Solution 1

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 System.AccessViolationException from unmanaged code?, 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.

Solution 2

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.

Share:
13,698
mpen
Author by

mpen

Updated on July 20, 2022

Comments

  • mpen
    mpen almost 2 years

    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?

  • Brian Beckett
    Brian Beckett over 13 years
    We had this exact problem once and it took us ages to figure out. It's worth checking for.
  • RED SOFT ADAIR
    RED SOFT ADAIR over 13 years
    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.
  • mpen
    mpen over 13 years
    @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.
  • John Zabroski
    John Zabroski over 7 years
    what do you do if you have an AccessViolationException in a .NET 4 app that actually hits a catch block unexpectedly? Yes, this is really happening to me right now. Couldn't believe it myself. Plan to ask a separate StackOverflow question but I read this answer first. Because the application doesn't crash, there is no crash dump to take, right?
  • Sean Fausett
    Sean Fausett over 7 years
    @JohnZabroski I would fallback to debugging with WinDbg and SOS[EX]. See my other answer linked to above.
  • John Zabroski
    John Zabroski over 7 years
    Thanks, I described my issue in detail here: stackoverflow.com/questions/39378849/…