Exception handling in the .NET Task Parallel Library with C#: a safety catch-all
November 6, 2015 2 Comments
Introduction
There can be situations that your application uses threads to such an extent that you either cannot put a try-catch block around every single Task.Wait, Task.WaitAll etc. calls or you simply forget it. There is a way to subscribe to all unhandled aggregate exceptions that the task scheduler encounters. You can then decide what to do with the exception there.
The task scheduler has an UnobservedTaskException event. It’s straightforward to subscribe to that even with the += operator.