Possible bug: Wrong "Unreachable code detected" warning in loop with try/catch block

  • Thread starter Thread starter Alex Broitman
  • Start date Start date
A

Alex Broitman

Guest
for (int attempt = 1; ; attempt++)
{
try
{
DoSomething();
return;
}
catch (Exception) when (attempt == 5)
{
throw;
}
}


For the above example I get "CS0162: Unreachable code detected" warning in the first line on "attempt++".

Is this a bug or I've missed something?

Continue reading...
 

Similar threads

C
Replies
0
Views
113
Carlo Goretti
C
S
Replies
0
Views
116
Stan Huang at Taiwan
S
W
Replies
0
Views
92
want 2 Learn
W
W
Replies
0
Views
81
want 2 Learn
W
Back
Top