Skip to content

Exception extensions

halcharger edited this page Apr 2, 2014 · 2 revisions

#####ExceptionExtensions.GetBaseException

Often when handling exceptions you are only interested in the original exception thrown in the stack. In a multi-level exception stack Exception.InnerException only returns the Exception one level down in the stack. you could use Exception.InnerException.InnerException... but this requires you knowing exactly how deep the Exception stack is. Now you can write the following:

catch(Exception ex)
{
	logger.Error(ex.GetBaseException());
}
Clone this wiki locally