Skip to content

Instantly share code, notes, and snippets.

@defaultlocale

defaultlocale/Main.java

Last active Oct 11, 2017
Embed
What would you like to do?
Пример компиляции 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
You can’t perform that action at this time.