私は何か間違ったことをしていると確信していますが、新しいスレッドタスクの例外処理のこの例を試してみると、ユーザーコードによって例外が処理されないままになります。コードの要点は、タスクのエラーをキャッチする方法の例を示すことです。
リンク:タスク例外の例
static void Main(string[] args)
{
var task1 = Task.Factory.StartNew(() =>
{
throw new MyCustomException("I'm bad, but not too bad!");
});
try
{
task1.Wait();
}
catch (AggregateException ae)
{
// Assume we know what's going on with this particular exception.
// Rethrow anything else. AggregateException.Handle provides
// another way to express this. See later example.
foreach (var e in ae.InnerExceptions)
{
if (e is MyCustomException)
{
Console.WriteLine(e.Message);
}
else
{
throw;
}
}
}
}
ほとんどの場合、ユーザーエラーは何がわからないか(Visual Studio 2012を使用)。