public static < T > void applyToAllWhileSuppressingExceptions ( Iterable < T > inputs , ThrowingConsumer < T , ? extends Exception > throwingConsumer ) throws Exception { if ( inputs != null && throwingConsumer != null ) { Exception exception = null ; for ( T input : inputs ) { if ( input != null ) { try { throwingConsumer . accept ( input ) ; } catch ( Exception ex ) { exception = ExceptionUtils . firstOrSuppressed ( ex , exception ) ; } } } if ( exception != null ) { throw exception ; } } }
This method supplies all elements from the input to the consumer . Exceptions that happen on elements are suppressed until all elements are processed . If exceptions happened for one or more of the inputs they are reported in a combining suppressed exception .