Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created March 18, 2020 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tluyben/560c3afe66a5b5a6950483c211957205 to your computer and use it in GitHub Desktop.
Save tluyben/560c3afe66a5b5a6950483c211957205 to your computer and use it in GitHub Desktop.
retry after error
const int RETRIES = 3;
void Retry(Action f)
{
for (int i = 0; i < RETRIES; i++)
{
try
{
f();
}
catch (Exception e)
{
if (i + 1 >= RETRIES)
throw e;
}
}
}
R Retry<R>(Func<R> f)
{
for(int i=0;i<RETRIES;i++)
{
try
{
return f();
}
catch(Exception e)
{
if (i + 1 >= RETRIES)
throw e;
}
}
return default(R);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment