Skip to content

Instantly share code, notes, and snippets.

@mackato
Created February 22, 2011 10:28
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 mackato/838477 to your computer and use it in GitHub Desktop.
Save mackato/838477 to your computer and use it in GitHub Desktop.
class TestFinally {
int num;
public static void main(String[] args) {
TestFinally test = new TestFinally();
int ret = test.increment();
assert ret == 1;
assert test.num == 2;
System.out.println("Done.");
}
public TestFinally() {
num = 0;
}
public int increment() {
int ret = 0;
try {
throw new RuntimeException("Error");
} catch (RuntimeException e) {
num++; ret++;
return ret;
} finally {
num++; ret++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment