我正在尝试运行以下代码:
- 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);
- }
- }
- }
我预计异常将被捕获在以下位置:
- catch (AggregateException aex)
- {
- Console.Write(aex.InnerException.Message);
- }
但这不会发生.为什么会这样?