Last active
October 11, 2017 12:17
-
-
Save defaultlocale/b9124ce93dfcd41152108895f1467546 to your computer and use it in GitHub Desktop.
Пример компиляции try-catch-finally
This file contains 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
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