Well, no matter how hard we try to write error-free code, the real world intervenes and inevitably there are exceptions that our code will encounter, for example, file not found, argument out or range, and so on. When we are processing a parallel loop command, since all of the iterations are running on potentially different threads, we need a way to gather all of the exceptions that any of the iterations of the loop may produce.
.NET provides the
AggregateException class for just this purpose. This allows us to collect all of the exceptions into the
AggregateException object and then "catch" it once the loop has completed.
Think of this like you would a normal error-handling situation. Typically, you put a ...