(CTPではなく、ベータ版を使用しているためTaskEx
、Task
.
using System;
using System.Threading.Tasks;
class Test
{
static void Main()
{
Task t = Foo();
t.Wait();
}
static async Task Foo()
{
try
{
await Task.Run(() => { throw new Exception(); });
}
catch (Exception e)
{
Console.WriteLine("Bang! " + e);
}
}
出力:
Bang! System.Exception: Exception of type 'System.Exception' was thrown.
at Test.<Foo>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
.HandleNonSuccessAndDebuggerNotification(Task task)
at Test.<Foo>d__2.MoveNext()
同じコードはあなたのマシンで何をしますか?