处理多个异常集合的 C++ 方法?

C++ approach to handling a collection of multiple exceptions?

在 C++17 中,什么是正确的 pattern/approach 来处理多个异常的集合?

是否有与 C# 等效的 C++ AggregateException Class

(我知道流控制异常是一种反模式。)

这不是我在 C++ 中看到的常见问题。如果您计划使用某个库进行 multithread/multicore 处理,您可能不想查看该库提供的内容或如何处理异常。如果您自己只需要这种功能,您可以执行以下操作(伪代码):

struct AggregateExcpetions {
  std::vector< std::variant< exception_type_1, exception_type_2, exception_type_3 > > m_exceptions;
}

与其使用变体,不如使用通用基数 class 更容易 - 例如 std::exception 或者 std::runtime_error.

struct AggregateExcpetions {
  std::vector< std::unique_ptr<std::exception> > m_exceptions;
}