Skip to content

Instantly share code, notes, and snippets.

@asottile
Created March 20, 2013 15:47
Show Gist options
  • Save asottile/5205766 to your computer and use it in GitHub Desktop.
Save asottile/5205766 to your computer and use it in GitHub Desktop.
Ghetto Retry for c++
#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