Task.Factory.StartNew 메서드에 의해 throw 될 NullReferenceException을 catch하려고합니다. 나는 그것이 task.Wait() 메소드로 'try'문장에 의해 잡혀 야한다고 생각한다. 나는 또한 Why is this exception not caught?을 언급했으나 전혀 모른다. 너 지혜를 나누 겠니?AggregateException이 Task.Wait()에 걸리지 않았습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Csharp_study
{
class Program
{
static void Main(string[] args)
{
Task my_task = Task.Factory.StartNew(() => { throw null; });
try
{
my_task.Wait();
}
catch (AggregateException exc)
{
exc.Handle((x) =>
{
Console.WriteLine(exc.InnerException.Message);
return true;
});
}
Console.ReadLine();
}
}
}
감사합니다. 사실 저는 아래의 의견을 들었을 때 3 개월 전에 답을 찾았습니다. 그러나 나는 그 질문을 끝내는 길을 찾을 수 없었다. 그래서 나는 당신을 하나의 것으로 표시합니다. 좋은 하루 되세요! –