A comment (by user soc) on an answer to a question about tail call optimisation mentioned that Java 7 has a new feature called \"suppressed exceptions\", because of \"the ad
Suppressed exceptions are additional exceptions that occur within a try-with-resources statement (introduced in Java 7) when AutoCloseable resources are closed. Because multiple exceptions may occur while closing AutoCloseable
resources, additional exceptions are attached to a primary exception as suppressed exceptions.
Looking at the bytecode of a piece of try-with-resources sample code, standard JVM exception handlers are used to accommodate the try-with-resources semantics.
You can suppress Exceptions in Java 6 as well (a little trickery involved),
I created a utility that transparently handles suppressing exception in Java 1.6 and Java 1.7. You can find the implementation here
All you need is to call:
public static <T extends Throwable> T suppress(final T t, final Throwable suppressed)
to supress a exception, and
public static Throwable [] getSuppressed(final Throwable t) {
to get the suppressed exceptions of a Exception, in case anybody still uses Java 1.6