Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I catch an exception that occurs anywhere in a Windows Forms application?

You can handle the Application.ThreadException event from the System.Windows.Forms namespace.

using System.Threading;

[STAThread] 
public static void Main() 
{ 
  Application.ThreadException +=
    new ThreadExceptionEventHandler( UnhandledExceptionCatcher ); 
  Application.Run( new Form1() ); 
} 

private static void UnhandledExceptionCatcher(object sender,
  ThreadExceptionEventArgs e) 
{ 
  Console.WriteLine( "Caught an unhandled exception" ); 
} 

See Application.ThreadException in the .NET Framework Class Library for a more detailed sample in both VB and C#.

Contributed from George Shepherd's Windows Forms FAQ



Page view counter