O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

AggregateException

Exceptions are dealt with on a per-thread basis. However, with an increased emphasis on parallel computing, the situation of having multiple exceptions flowing on different threads becomes a new challenge. When an API spawns parallel tasks and multiple exceptions are thrown from the different executing tasks, you want to be able to analyze all those when the parallel operation completes.

A good example is the System.Threading parallel constructs introduced in .NET 4.0, including parallel loop constructs exposed on the Parallel static class:

Parallel.For(0, 10, i => {    if (i % 2 == 0)        throw new Exception("Even number!");    // Do meaningful work.});

The preceding code spawns parallel tasks ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required