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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.