I\'m working with some classes which, when throwing, have a relatively deep InnerException tree. I\'d like to log and act upon the innermost exception which is the one having th
You could use the GetBaseException method. Very quick example:
try
{
try
{
throw new ArgumentException("Innermost exception");
}
catch (Exception ex)
{
throw new Exception("Wrapper 1",ex);
}
}
catch (Exception ex)
{
// Writes out the ArgumentException details
Console.WriteLine(ex.GetBaseException().ToString());
}