2

I have these lines in my App.xaml.cs, to globally catch the exceptions:

this.Dispatcher.UnhandledException += new
    DispatcherUnhandledExceptionEventHandler(
        Current_DispatcherUnhandledException);
AppDomain.CurrentDomain.UnhandledException += new
    UnhandledExceptionEventHandler(
        CurrentDomain_UnhandledException);
Application.Current.DispatcherUnhandledException += new
    DispatcherUnhandledExceptionEventHandler(
        Current_DispatcherUnhandledException);

Most exceptions can be caught and a log file will be generated so that I know what is causing the error. But on my customer's PC (only windows 8 has this problem), the WPF application sometimes crashed but I was not able to get the exception log, means the exception handlers above was not called.

Is there any handler I can set to catch exception? Or is there any log collector/reader like android DDMS for Windows/WPF app?

Thank you!

DrKoch
  • 9,556
  • 2
  • 34
  • 43
user3162662
  • 743
  • 1
  • 7
  • 20
  • Have you debug the code for that specific exception ? Or you can refer to the exception stack in app crash popup. Also you can view the exception stack in Event Viewer. – Rohit Prakash Jan 19 '15 at 04:36
  • 1
    There are ways to crash a program that don't involved throwing managed exceptions. Unfortunately, there is not enough detail in your question to understand what the specific issue is, and whether it is realistic to think you can trap whatever error is actually happening. – Peter Duniho Jan 19 '15 at 06:31
  • Another uncatchable Exception is StackOverflowException – DrKoch Jan 19 '15 at 06:33
  • Look into `Windows Event Viewer->Windows Logs->Application` for the error information if your exception handler does not catch it. – kennyzx Jan 19 '15 at 07:06
  • See http://stackoverflow.com/questions/4223470/c-sharp-not-catching-unhandled-exceptions-from-unmanaged-c-dll on handling unmanaged exceptions – Emond Jan 19 '15 at 07:10
  • Thanks everyone. In my case it was Access Violation Exception that happened from a C library. No wonder it cannot be caught. Anyway, the issue has been solved. – user3162662 Jan 22 '15 at 07:47

1 Answers1

1

Since .NET 4.0 you could try and HandleProcessCorruptedStateExceptionsAttribute This attribute allows you to handle exceptions that since .Net 4 terminate the process. This is rather dangerous as you are allowing a process to continue (handle the exception) even when its memory has become corrupted.

In general: do not trust the application after catching such an exception. Log the exception and stop the application. Only when you know what is causing the exception and you are sure the application can recover you could apply this attribute to a method and make it resume normal execution.

Emond
  • 50,210
  • 11
  • 84
  • 115