Created
March 6, 2018 14:48
-
-
Save glebov21/acaee39cb8bf30c65fb887991932f502 to your computer and use it in GitHub Desktop.
Try Again If Exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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