public SuppressingCloser(Throwable mainThrowable) { state = new State(); state.addThrowable( this, mainThrowable ); }
/** * If the given {@code objectToClose} is non-null, * execute the given close {@code operator} <strong>immediately</strong> on {@code objectToClose}, * swallowing any throwable in order to * {@link Throwable#addSuppressed(Throwable) add it as suppressed} to a previously caught throwable, * or to re-throw it later. * @param operator An operator to close {@code objectToClose}. Accepts lambdas * such as {@code MyType::close}. * @param objectToClose An object to close. * @return {@code this}, for method chaining. */ public <T> S push(ClosingOperator<T, ? extends E> operator, T objectToClose) { try { if ( objectToClose != null ) { operator.close( objectToClose ); } } catch (Throwable t) { getState().addThrowable( this, t ); } return getSelf(); }