我正在尝试运行以下代码:
class Program
{
static void Main(string[] args)
{
var task = Task.Factory.StartNew(() =>
{
throw new ApplicationException("message");
});
try
{
task.ContinueWith(t => Console.WriteLine("End"));
}
catch (AggregateException aex)
{
Console.Write(aex.InnerException.Message);
}
}
}
我预计Exception
会在以下位置被捕获:
catch (AggregateException aex)
{
Console.Write(aex.InnerException.Message);
}
但这并没有发生。为什么会这样?