import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.function.Consumer;

public class CollectionExceptionsDemo {
    @FunctionalInterface
    interface IOAction<T> {
        void execute(T value) throws IOException;
    }

    static <T> Consumer<T> propagate(IOAction<T> action) {
        return value -> {
            try {
                action.execute(value);
            } catch (IOException error) {
                throw new UncheckedIOException(error);
            }
        };
    }

    static void read(String name) throws IOException {
        if (name.equals("missing")) {
            throw new IOException("archive absent");
        }
        System.out.println("read: " + name);
    }

    public static void main(String[] args) {
        List<String> names = List.of("catalog", "missing", "history");
        try {
            names.forEach(propagate(CollectionExceptionsDemo::read));
        } catch (UncheckedIOException error) {
            System.out.println("interrupted: " + error.getCause().getMessage());
        }

        for (String name : names) {
            try {
                read(name);
            } catch (IOException error) {
                System.out.println("skipped: " + name);
            }
        }
    }
}
