Come to work with exception throwing methods in streams?

This question might be a bit old, but because I think the “right” answer here is just one way it can lead to some hidden problems later in your code. Even if there is a small one controversy checked exceptions exist for a reason.

The most elegant way in my opinion may have been found by Misha here Aggregated runtime exceptions in Java 8 streams by simply performing the actions in “future”. This way you can run all parts of work and collect non-functioning exceptions as a single one. Otherwise you could collect them all in a List and process them later.

A similar approach derives from Benji Weber . It suggests making your own type to collect working and non-working parts.

Depending on what you really want to get a simple mapping between Input Values ​​and Output Values, the exceptions might work for you too.

If you don’t like one of these ways, consider using (depending on the Original Exception) at least one of your own exceptions.

Leave a comment