Fetch unhandled exceptions in C#

using System;
 
namespace SomeNamespace {
 
	[STAThread]
	static class Program
	{
		private static void Main()
        {
			// Trace all unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(Program.OnUnhandledException);
		}
	}
 
	///<summary>
	/// Event handler for unhandled exceptions
	///</summary>
	private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
	{
		Exception exceptionObject = e.ExceptionObject as Exception;
		// Do something with the unhandled exception here
	}
}

Download this snippet

Registers an event handler for all unhandled exceptions that are thrown during runtime.

Twitter Twitter

3 Comments to “ Fetch unhandled exceptions in C#”

  1. Anonymous  on Sep 25, 2009

    Jp6b98 <a href="http://lmpumhnycgak.com/">lmpumhnycgak</a>, [url=http://ujakjnkdspcf.com/]ujakjnkdspcf[/url], [link=http://ivrgbrxmnvij.com/]ivrgbrxmnvij[/link], http://ujapjdexexds.com/

  2. Anonymous  on Jan 22, 2010

    YRG9ao <a href="http://hptwhrkzdpkz.com/">hptwhrkzdpkz</a>, [url=http://wmhogsqeabem.com/]wmhogsqeabem[/url], [link=http://ahocpqirgonw.com/]ahocpqirgonw[/link], http://cfecrgsgcres.com/

  3. Anonymous  on Mar 14, 2010

    cElnl7 <a href="http://qdjhowyaufbv.com/">qdjhowyaufbv</a>, [url=http://njmjdwpllkcm.com/]njmjdwpllkcm[/url], [link=http://achwaciatjxu.com/]achwaciatjxu[/link], http://wxfpjwpbhywx.com/

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>