using System;
using System.Threading.Tasks;
public class Program
{
public static void Main()
{
var p = new Program();
p.Loop();
}
public async void Loop()
{
for (int i = 0; i < 5; ++i)
{
try
{
Console.WriteLine(i);
var result = await SomeTask();
Console.WriteLine(result);
}
catch (Exception)
{
Console.WriteLine("Error" + i);
}
}
}
public async Task<string> SomeTask()
{
await Task.Delay(1);
throw new Exception();
return "Result";
}
}
Output
0
Error0
1
I would expect the output to be more like this:
0
Error0
1
Error2
2
Error2
3
Error4
4
Why does it stop after 0?