Unwrapping AggregateExceptions

What about tasks that have multiple exceptions? As you might recall from Chapter 30, you can use Task objects for parallel computing where multiple units of work can fail. A good example of this behavior is the use of the Parallel class to run multiple loop iterations in parallel. To capture all possible exception states, the AggregateException type was introduced in .NET 4.0. Handling such an exception can be quite tedious, though, because regular catch blocks cannot be used to inspect any of the object’s inner exceptions. Instead, a Handle method has to be called, specifying a handler method through a delegate.

Nowadays, tasks are increasingly commonly used as futures that represent the eventual completion of ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.