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

标签 c# multithreading exception exception-handling task

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

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

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

最佳答案

它只是原始异常中的一个 non-AggregateExceptions。因此,例如,如果您有一个初始 AggregateException 为:

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

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

基本上 InnerException 对于 AggregateException 不是很有用。记录 所有 InnerExceptions... 或仅在顶级异常上调用 ToString() 会更有用,这将保留所有结构...

关于c# - AggregateException - AggregateException.Flatten().InnerException 代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13570855/

相关文章:

java - ThreadPoolExecutor 在关闭之前未完全执行线程

c# - 执行文件io时如何正确处理异常

c# - 身份服务器单点注销,也从服务器注销

multithreading - 如何在多线程时安全地访问和修改数组?

c# - 绑定(bind)到 ObservableCollection<string>

java - java中允许特定数量的用户访问某个方法

exception - Hadoop:任务跟踪器不会启动 java.io.IOException

ios - 由CONTAINS谓词引起的异常

c# - 单元测试抛出异常如何获得100%的覆盖率?

c# - 如何在无序列表中添加项目?