import javax.naming.NamingException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
import java.rmi.activation.ActivationException;
import java.util.Arrays;

public class Main{

    public static void main(String[] args) throws NamingException {
        try {


            try(
                    DummyIO dummy = new DummyIO(false,true); //-- try with different true, false values
            ){
                throw new ActivationException();
            } catch (IOException | ActivationException e1){
                System.out.println("Inner: Caught: " + e1);
                System.out.println("Inner: suppressed: " + Arrays.toString(e1.getSuppressed()));
                throw new SecurityException(e1);
            }finally {
                throw new NamingException();
            }


        }catch (NamingException e2){
            System.out.println("Outer: Caught: " + e2);
            System.out.println("Outer: suppressed: " + Arrays.toString(e2.getSuppressed()));
        }

    }


    private static class DummyIO implements AutoCloseable{
        private boolean throwInClose;

        private DummyIO(boolean throwInConstructor, boolean throwInClose) throws FileNotFoundException {
            if(throwInConstructor){
                throw new FileNotFoundException();
            }
            this.throwInClose = throwInClose;
        }

        @Override
        public void close() throws Exception {
            if(throwInClose){
                throw new ClosedChannelException();
            }
        }
    }

}