Created
April 2, 2014 09:36
-
-
Save yanhua365/9930968 to your computer and use it in GitHub Desktop.
实现出错后多次重新执行的java代码,可以为代码加入容错机制(比如远程调用时就很实用)。
This file contains hidden or 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
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