I've code that rethrows an exception.
When I later read the exception from task.Exception, its stacktrace points to the location where I re-threw the exception (line n and not line m, as I expected).
Why is this so? bug in TPL or more likely something I have overlooked.
As I workaround I can wrap the exception as the inner-exception in a new exception.
internal class Program
{
private static void Main(string[] args)
{
Task.Factory.StartNew(TaskMethod).ContinueWith(t => Console.WriteLine(t.Exception.InnerException));
Console.Read();
}
private static void TaskMethod()
{
try
{
line m: throw new Exception("Todo");
}
catch (Exception)
{
line n: throw;
}
}
}