Method

Java Throwable.getSuppressed()

Returns suppressed exceptions, or an empty array when none are recorded.

Formal Syntax & Structure

java syntaxjava
public final Throwable[] getSuppressed()

Working Example

Example Snippetjava
import java.io.IOException;class FailingLease implements AutoCloseable {    void use() throws IOException { throw new IOException("Read failed"); }    public void close() throws IOException { throw new IOException("Close failed"); }}public class Main {    public static void main(String[] args) {        try (FailingLease lease = new FailingLease()) { lease.use(); }        catch (IOException e) {            System.out.println(e.getMessage());            System.out.println(e.getSuppressed()[0].getMessage());        }    }}
Java Reference