2

I've got a bug that is really difficult for me to track. It's one of those that only occurs when the debugger isnt connected :)

I've pinvoked MiniDumpWriteDump() and that works really well for creating .dmp files that I can debug after the fact.

however, I'm doing something like

try
{
    foo();
}
catch(Exception)
{
    CreateMiniDump()
}

this works great, however I dont get the callstack that is desired. I'd really prefer to have the callstack (with all the member variables) at the point where the exception was thrown.

is this possible? Is there a mechanism to get first dibs on the exception? such that I can create a minidump and preserve the callstack, etc?

stuck
  • 2,264
  • 2
  • 28
  • 62
  • See [this question and answer](http://stackoverflow.com/a/11898263/588306) about how to configure windows to save full crash dumps. – Deanna Sep 10 '12 at 09:35

2 Answers2

2

You can subscribe to AppDomain.CurrentDomain.UnhandledException to get an event that is raised when an exception is about to unwind. When it's raised, the original context is still on the stack. You could put your minidump creation code inside of your event handler.

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
2

In .NET 4 and up you can subscribe to the FirstChanceException event.

Logan Capaldo
  • 39,555
  • 5
  • 63
  • 78