This is a sample code from a "C# 5.0 in a Nutshell"
TaskCreationOptions atp = TaskCreationOptions.AttachedToParent;
Task.Factory.StartNew (() =>
{
Task.Factory.StartNew (() => { throw null; }, atp);
Task.Factory.StartNew (() => { throw null; }, atp);
Task.Factory.StartNew (() => { throw null; }, atp);
})
.ContinueWith (p => Console.WriteLine (p.Exception),
TaskContinuationOptions.OnlyOnFaulted);
I have a "CLR exceptions": "break on user-unhandled" option checked in my VS2012 settings and running this code provides a VS's "NRE exception was unhandled by user code" popup on the throw null;
I've tried to try-catch exception on Wait in the ContinueWith and later but still got the unhandled exception.
I feel like a solution with turning "CLR exceptions": "break on user-unhandled" off seems wrong, because I actually handle this exception. So what is the right way to manage it?