Hi everybody,
at the moment I am trying some of the new Features of the Task Parallel Library, shipped with the .Net Framework 4.0 Beta 2.
My question relates specifically to the Exception Handling within the TPL as described here: http://msdn.microsoft.com/en-us/library/dd997415%28VS.100%29.aspx
First example (changed it a little bit):
static void Main(string[] args)
{
var task1 = Task.Factory.StartNew(() =>
{
throw new Exception("I'm bad, but not too bad!"); // Unhandled Exception here...
});
try
{
task1.Wait(); // Exception is not handled here....
}
catch (AggregateException ae)
{
foreach (var e in ae.InnerExceptions)
{
Console.WriteLine(e.Message);
}
}
Console.ReadLine();
}
According to the documentation the Exception should be propagated back
to the to the joining thread which calls: task1.Wait()
.
But I always get an Unhandled Exception within:
var task1 = Task.Factory.StartNew(() =>
{
throw new MyCustomException("I'm bad, but not too bad!");
});
Could someone explain to me why, or does someone know if there has sth. changed since the release of Beta 2?