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 AggregateException
of:
AggregateException
AggregateException
IOException("x")
IOException("y")
IOException("z")
Then the InnerException
of the flattened result would come out as either IOException("x")
, IOException("y")
or IOException("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 the InnerExceptions
on the flattened version, but that should be seen as a union of all the original non-AggregateExceptions, with no guaranteed order.
Basically InnerException
isn't terribly useful for AggregateException
. It would be far more useful to log all the InnerExceptions
... or just call ToString()
on the top-level exception, which would keep all the structure...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With