Skip to content

Instantly share code, notes, and snippets.

@defaultlocale
Last active October 11, 2017 12:17
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 defaultlocale/b9124ce93dfcd41152108895f1467546 to your computer and use it in GitHub Desktop.
Save defaultlocale/b9124ce93dfcd41152108895f1467546 to your computer and use it in GitHub Desktop.
Пример компиляции try-catch-finally
public class Main {
public static void main(String[] args) {
new Main().execute();
}
public void execute() {
System.out.println(run());
}
public int run() {
try {
if (isSomething()) {
return foo();
}
return bar();
} catch (FooException e) {
handle(e);
} finally {
return finallyValue();
}
}
public int foo() {
return 2;
}
public int bar() throws FooException {
if (isSomething()) {
throw new FooException();
}
return 3;
}
public boolean isSomething() {
return true;
}
public int finallyValue() {
return 1;
}
public void handle(FooException e) {
System.out.println(e);
}
public static class FooException extends Exception {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment