Skip to content

Instantly share code, notes, and snippets.

@semlinker
Last active November 6, 2019 11:01
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 semlinker/117dd87ef97a846cb22cb332cb5d1b99 to your computer and use it in GitHub Desktop.
Save semlinker/117dd87ef97a846cb22cb332cb5d1b99 to your computer and use it in GitHub Desktop.
Java try-catch-finally
public class FinallyTest {
public void foo() {
try {
tryItOut();
} catch (MyException e) {
handleException(e);
} finally {
handleFinally();
}
}
private void tryItOut() throws MyException {
}
class MyException extends Exception {
}
private void handleException(MyException e) {
}
private void handleFinally() {
}
}
public class MultiException {
public void foo() {
try {
tryItOut();
} catch (MyException e) {
handleException(e);
} catch (MyException1 e) {
handleException1(e);
}
}
private void tryItOut() throws MyException, MyException1 {
}
class MyException extends Exception {
}
class MyException1 extends Exception {
}
private void handleException(MyException e) {
}
private void handleException1(MyException1 e) {
}
}
public class OneException {
public void foo() {
try {
tryItOut();
}
catch (MyException e) {
handleException(e);
}
}
private void tryItOut() throws MyException {
}
class MyException extends Exception {
}
private void handleException(MyException e) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment