AggregateException - AggregateException.Flatten().InnerException代表什么?

19

我一直在查看我们某个应用程序中的一些代码,它如下所示:

catch (AggregateException ae)
{
    this._logger.Log(ae.Flatten().InnerException.ToString(), Category.Exception, Priority.High);
}

我的问题是这样的。我知道AggregateException.Flatten()是什么,也知道AggregateException.Flatten().InnerExceptions代表什么。但是,AggregateException.Flatten().InnerException(单个)代表什么?

1个回答

39

它将只是原始异常中的一个非AggregateExceptions。因此,例如,如果您有一个初始的AggregateException

AggregateException
    AggregateException
        IOException("x")
        IOException("y")
    IOException("z")

那么,扁平化结果的InnerException将作为IOException("x")IOException("y")IOException("z")之一出现。我不相信会有任何关于它会是哪个的保证。(我认为当前行为会给出“z”版本...)它将是扁平化版本中第一个InnerExceptions,但应该将其视为所有原始非AggregateExceptions的联合,没有保证的顺序。

基本上说,对于AggregateException来说,InnerException并不是非常有用。记录所有InnerExceptions将会更有用...或者只需在顶层异常上调用ToString(),这将保留所有结构...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接