Exception must be caught or declared; already using try-catch and throws

Viewed 26

I'm trying to build an AutoClosable list to use with try-with-resources blocks. This is java 8. When I try to compile the following block of code:

public void close () throws Exception {
    try {
        closeableList.forEach(closeable -> closeable.close());
    } catch (Exception e) {
        throw e;
    }
}

I get an error:

AutoCloseableList.java:29: error: unreported exception Exception; must be caught or declared to be thrown [javac] closeableList.forEach(closeable -> closeable.close());

I've tried just catching the Exception without throwing it, and I've tried just having the for-each line without the try-catch block around it. Any way I try gives the same error. Help please!

0 Answers
Related