AggregateException을 발생시키지 않는 다음 코드가 있습니다. 누적 예외가 발생하지 않고 이유를 모르겠습니다. 일반적으로이 같은 집계 예외는 없습니다 Test()
을 실행하는 작업의 완성, 코드를 사용하여 작업TPL을 사용할 때 예외가 발생하지 않습니다.
Test2()
를 실행)하여 연속 작업의 완료를 기다리지 때문이다
class Program
{
static void Main(string[] args)
{
var task1 = Task.Factory.StartNew(() =>
{
Test();
}).ContinueWith((previousTask) =>
{
Test2();
});
try
{
task1.Wait();
}
catch (AggregateException ae)
{
foreach (var e in ae.InnerExceptions)
{
// Handle the custom exception.
if (e is CustomException)
{
Console.WriteLine(e.Message);
}
// Rethrow any other exception.
else
{
throw;
}
}
}
}
static void Test()
{
throw new CustomException("This exception is expected!");
}
static void Test2()
{
Console.WriteLine("Test2");
}
}
public class CustomException : Exception
{
public CustomException(String message) : base(message)
{ }
}
}
디버거가 코드에 기회가 있기 전에 잡기가 아닌지 확인하십시오. – BugFinder
디버거를 사용하지 않아도 같은 문제가 발생합니다. ''이 예외가 예상됩니다 .''' – codejunkie
코드가 기다림을 시도하기 전에 StartNew를 사용했기 때문에 Id가 생각했습니다. – BugFinder