I am using the Task Parallel Library for .NET 3.5 (a NuGet package).
When running the following code, the OnlyOnFaulted
task is not being run when an exception is thrown from MethodThrowsException()
:
var task = Task.Factory.StartNew<SomeType>(() =>
{
MethodThrowsException();
})
.ContinueWith(t =>
{
ExceptionMessageTextBox.Text = t.Exception.Message;
},
CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext());
I (eventually) get this exception:
System.AggregateException was unhandled
Message: An unhandled exception of type 'System.AggregateException' occurred in System.Threading.dll
Additional information: TaskExceptionHolder_UnhandledException
I cannot see where it is located as it is being thrown within System.Threading.dll (I would need to load the pdb).
As far as I can see, I am observing the exception correctly, as specified by this MSDN article.