Inner Classes and Exceptions

Exception Handling in Java: Try, Catch, Finally

1/34

Given:

public class Test {
    public static void main(String[] args) {
        try (SomeResource r = new SomeResource()) {
            throw new RuntimeException("RuntimeException");
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

class SomeResource implements java.io.Closeable {
    public void close() throws IOException {
        throw new IOException("Close Exception");
    }
}

Which exception will be thrown from the main?

Comments