Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.