In the code below, a false positive is reported in the “while” line regarding ‘numberOfTries’.
It does not take into account that the line ‘Int.Parse…’ could throw an exception, in which case the break will not be executed. The ‘Int.Parse’ is only an example and can be replaced by any other code that potentially throws an exception.
var path = @"C:\foo.txt";
int result = 0;
int numberOfTries = 0;
while( numberOfTries++ < 20 )
{
try
{
result = int.Parse( File.ReadAllText( path ) );
break;
}
catch
{
System.Threading.Thread.Sleep( 200 );
}
}