user1205398
user1205398

Reputation: 661

How to get the call stack when my WPF program is crashed

I have a WPF program, it crashes sometimes, I want to know the call stack (or some other information) when it crashes. How can I do this?
Great thanks.

================ updated: Finally, I can log the call stack using below method. register a handler to log the call stack when an unhandledexception has occurred.

In the main class, AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptions);

If you have other ideas, please share. Thanks.

Upvotes: 0

Views: 307

Answers (2)

musium
musium

Reputation: 3072

You could handle the UnhandledException event of the App class

protected override void OnStartup(StartupEventArgs e)
{
    AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
}
private void AppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    Log( e.ExceptionObject );
}

Upvotes: 2

Adam
Adam

Reputation: 1159

Have you tried stepping through the code in visual studio?

This should highlight the general area where the code fails.

Moving forward wrapping the affected area in a try...catch statement would allow you to print the contents of the exception and subsequently the stack trace.

Upvotes: 0

Related Questions