Created
March 20, 2013 15:47
-
-
Save asottile/5205766 to your computer and use it in GitHub Desktop.
Ghetto Retry for c++
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
#ifndef GHETTO_RETRY_H | |
#define GHETTO_RETRY_H | |
template<typename TEx, TCall> | |
void ghettoRetry(TCall call, int count = 1) { | |
// Retry count number of times | |
// Note the last one will throw on failure | |
for (int i = 0; i < count - 1; i += 1) { | |
try { | |
call(); | |
return; | |
} catch (const TEx&) { } | |
} | |
call(); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment