global exception handler

  • Thread starter Thread starter dave cardnell
  • Start date Start date
D

dave cardnell

I have the following code in my app

Application.ThreadException += new
ThreadExceptionEventHandler(Application_ThreadException);

Application.Run(new TestFrm());

public static void Application_ThreadException(
object sender, ThreadExceptionEventArgs e) {
Console.WriteLine("fred");
}

However any uncaught exception, doesn't end up in the
handler. I can get it to work in a test app.
Any ideas ?
 
dave said:
I have the following code in my app

Application.ThreadException += new
ThreadExceptionEventHandler(Application_ThreadException);

Application.Run(new TestFrm());

public static void Application_ThreadException(
object sender, ThreadExceptionEventArgs e) {
Console.WriteLine("fred");
}

However any uncaught exception, doesn't end up in the
handler. I can get it to work in a test app.
Any ideas ?


You have to add this:

AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(myHandlerMethod);
 
Erwin said:
You have to add this:

AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(myHandlerMethod);

Well, sort of. This will allow you to catch non-CLS-compliant
exceptions. All System.Exception derived types should have been caught
by ThreadExceptionHandler already.

Cheers,
 
Back
Top