Exception Handling

Handling exceptions is a crucial topic in parallel programming. The problem is that multiple tasks that run concurrently could raise more than one exception concurrently, and you need to understand what the actual problem is. The .NET Framework 4.6 offers the System.AggregateException class that wraps all exceptions that occurred concurrently into one instance. Such class then exposes, over classic properties, an InnerExceptions collection that you can iterate for checking which exceptions occurred. The following code demonstrates how you catch an AggregateException and how you iterate the instance, starting two tasks that attempt to access two files that do not exist:

Dim aTask = Task.Run(Sub() ...

Get Visual Basic 2015 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.