Finding out the Root Cause Exception


The other day, I was busy debugging an issue which did not seem to make sense. For some unknown reason, the developer of a particular client library was not a good citizen because he decided to swallow up an root exception and threw up his own vague exception without attaching the original exception as the InnerException.

That is when I managed to cross a very interesting event on the AppDomain object: the FirstChanceException event.

Attaching to this event allowed me the chance to figure out the root cause of the third party library using code such as the following:

AppDomain.CurrentDomain.FirstChanceException +=
	(source, e) =>
		{
			Console.WriteLine("FirstChanceException event raised in {0}: {1}",
				AppDomain.CurrentDomain.FriendlyName, e.Exception.Message);
		}

Check out the documentation out at MSDN.

blog comments powered by Disqus