Skip to content

Instantly share code, notes, and snippets.

@yanhua365
Created April 2, 2014 09:36
Show Gist options
  • Save yanhua365/9930968 to your computer and use it in GitHub Desktop.
Save yanhua365/9930968 to your computer and use it in GitHub Desktop.
实现出错后多次重新执行的java代码,可以为代码加入容错机制(比如远程调用时就很实用)。
int count = 0;
int maxTries = 3;
while(true) {
try {
// Some Code
// break out of loop, on success
} catch (SomeException e) {
// handle exception
if (++count == maxTries) throw e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment