Skip to content

Instantly share code, notes, and snippets.

@georgy7
Last active March 25, 2017 00:47
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 georgy7/4615e54f379e1058f1846cf48b73f141 to your computer and use it in GitHub Desktop.
Save georgy7/4615e54f379e1058f1846cf48b73f141 to your computer and use it in GitHub Desktop.
bool read = false;
int tries = 0;
while (!read && tries < 5) {
try {
if (wrongFoot) {
throw new GotUpOnTheWrongFoot();
}
// Yes, I really doesn't care if something
// much deeper in it throws the exception.
readTheStream();
read = true;
} catch (InterruptedInputException e) {
logIt();
tries++;
} catch (GotUpOnTheWrongFoot e) {
useDifferentFoot();
}
}
if (!read) {
throw new UnreachebleThing(); // or return null/empty
}
return theData;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment