Live Chat Icon For mobile
Live Chat Icon

How can I catch an exception on a program wide basis

Platform: WinForms| Category: General

You can handle the Application.ThreadException event. See the FrameWork class library for a more detailed sample in both VB and C#.

	public static void Main() 
		Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(UnhandledExceptionCatcher);
		Application.Run(new Form1());

	private static void UnhandledExceptionCatcher(object sender, System.Threading.ThreadExceptionEventArgs e)
		Console.WriteLine('caught an unhandled exception.');

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.