Skip to content

Instantly share code, notes, and snippets.

@glebov21
Created March 6, 2018 14:48
Show Gist options
  • Save glebov21/acaee39cb8bf30c65fb887991932f502 to your computer and use it in GitHub Desktop.
Save glebov21/acaee39cb8bf30c65fb887991932f502 to your computer and use it in GitHub Desktop.
Try Again If Exception
private bool TryAgainIfException(Action action, int attemts = 10)
{
while (attemts > 0)
{
try
{
action();
return true;
}
catch (Exception e)
{
if(attemts == 1)
AutogrammaMainLogger.LogError("Exception: " + e.Message);
else
AutogrammaMainLogger.LogWarning("Exception: " + e.Message);
attemts--;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment