I’ve been looking at some code in one of our applications that looks as follows:
catch (AggregateException ae)
{
this._logger.Log(ae.Flatten().InnerException.ToString(), Category.Exception, Priority.High);
}
My question is this. I know what AggregateException.Flatten() does, and I know what AggregateException.Flatten().InnerExceptions represents. However, what does AggregateException.Flatten().InnerException (single) represent?
It will just be one of the non-AggregateExceptions within the original exception. So for example, if you have an initial
AggregateExceptionof:Then the
InnerExceptionof the flattened result would come out as eitherIOException("x"),IOException("y")orIOException("z"). I don’t believe there’s any guarantee about which it would be. (I believe the current behaviour would give the “z” version at the moment…) It will be the first of theInnerExceptionson the flattened version, but that should be seen as a union of all the original non-AggregateExceptions, with no guaranteed order.Basically
InnerExceptionisn’t terribly useful forAggregateException. It would be far more useful to log all theInnerExceptions… or just callToString()on the top-level exception, which would keep all the structure…