Home page

Exceptions in Java

Apr 2, 2013, 15:11

What is the result of this code?

Task 1.

public static void m() {
try {
    throw new Exception();
} catch (Exception e) {
    System.out.println("catch");
} finally {
    System.out.println("finally");
}

Task 2.

int i = 0;
try {
    throw new Exception();
} catch (Exception e) {
    i = 10;
    return i;
} finally {
    i = 20;
}

Task 3.

int i = 0;
try {
    throw new Exception();
} catch (Exception e) {
    i = 10;
    return i;
} finally {
    i = 20;
    return i;
}
Your comment
won’t be published

HTML will not work

Ctrl + Enter