Skip to content

Instantly share code, notes, and snippets.

@ssippe
Created October 30, 2018 05:21
Show Gist options
  • Save ssippe/77b8397d7b398225d8d6c0aa668dfbeb to your computer and use it in GitHub Desktop.
Save ssippe/77b8397d7b398225d8d6c0aa668dfbeb to your computer and use it in GitHub Desktop.
AggregateException Pattern
public void ProcessList(List<Input> inputs)
{
var errors = new List<Exception>();
foreach (var input in inputs)
{
try
{
Process(input);
}
catch (Exception ex)
{
errors.Add(new Exception($"error processing {input}", ex));
//Continue processing the rest of the list and throw the
//any exceptions at the end.
}
}
if (errors.Any())
{
throw new AggregateException($"{errors.Count} of {inputs.Count} failed", errors);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment