public void DoRiskyThings(List<Action> tasks)
{
List<Exception> exceptions = new List<Exception>();
foreach(Action task in tasks)
{
try {task()}
catch (Exception e) {exceptions.Add(e)};
}
if (exceptions.Any())
{
//... what goes here?
}
}
我想保留所有信息(尤其是消息和堆栈跟踪)。
最佳答案
您正在寻找 AggregateException
class .
关于c# - 发生了多个异常,重新抛出的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9438131/