Is there a C# equivalent of Java's Thread.setDefaultUncaughtExceptionHandler()
?
views:
67answers:
2
+6
A:
There's AppDomain.UnhandledException
for non-WinForms, and Application.ThreadException
for WinForms.
They're unlikely to be exactly equivalent to the Java handler, but they may do what you need.
Jon Skeet
2009-09-02 22:32:07
Noteworthy: "you'll get the standard .NET crash dialog in a console app, even if you've registered an unhandled exception handler for your AppDomain" http://www.codinghorror.com/blog/archives/000201.html
dtb
2009-09-02 22:36:00
@dtb - Thanks, I just found that out. :-)
Taylor Leese
2009-09-02 22:39:31
A:
something like this ?
in your main method use this
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
declare this
public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
... code goes here ...
}
That should handle any thread exceptions in a win-forms app, for console take a look at the AppDomain handler detailed by the poster above.
krystan honour
2009-09-02 22:56:56