global exception handler

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 ?
 
E

Erwin Stadler

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);
 
J

Joerg Jooss

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top