Interface CloseableScope

    • Method Detail

      • close

        void close()
        Closes this scope or other closeable resource. This is a specialization of AutoCloseable.close() that throws only unchecked exceptions.
        Specified by:
        close in interface AutoCloseable
      • andThen

        default CloseableScope andThen​(Runnable action)
        Creates extended CloseableScope that additionally runs specified action unless exception is thrown. This is useful for quickly creating outer scopes that add extra operations to some inner scope. If close() throws, action does not run.
        Parameters:
        action - the operation to perform after close() is called
        Returns:
        new CloseableScope that, when closed, first closes this CloseableScope and then executes action
        Throws:
        NullPointerException - if action is null
        See Also:
        andFinally(Runnable)
      • andFinally

        default CloseableScope andFinally​(Runnable action)
        Creates extended CloseableScope that additionally runs specified action regardless of exceptions. This is useful for quickly creating outer scopes that add extra operations to some inner scope. If close() throws, action runs anyway as if in try-with-resources block. If both close()} and action throw, the exception from action is added to suppressed exception list by calling Throwable.addSuppressed(Throwable).
        Parameters:
        action - the operation to perform after close() is called
        Returns:
        new CloseableScope that, when closed, first closes this CloseableScope and then executes action
        Throws:
        NullPointerException - if action is null
        See Also:
        andThen(Runnable)