jOOL icon indicating copy to clipboard operation
jOOL copied to clipboard

Add Seq.peekThrowable(Consumer<Throwable>)

Open lukaseder opened this issue 9 years ago • 4 comments

There is currently no fluent way of handling exceptions in a Stream. While Stream extends AutoCloseable and provides an onClose(Runnable) hook for actions that are to be taken before the actual closing, there is no such thing for exceptions.

We should add an peekThrowable(Consumer<Throwable>) hook that allows Consumers to be added to consume all sorts of exceptions that may occur.

The actual API is not yet fully defined and may differ, e.g. by taking inspiration from the Try monad

lukaseder avatar Jun 01 '15 09:06 lukaseder

@lukaseder, do you have any thoughts on this? I believe, CompletableFuture's API is a rather well designed one, although a little bloated with (maybe) too much methods responsible for handling the computation result, so maybe this feature's implementation could borrow something from there?

tkroman avatar Sep 02 '15 21:09 tkroman

I haven't thought all situations through yet. I'm afraid that it might not be a very good idea to implement such a method in a Stream. Perhaps, there are situations where exceptions will escape...

lukaseder avatar Sep 03 '15 15:09 lukaseder

An implementation suggestion was made by @tlinkowski in https://github.com/jOOQ/jOOL/pull/299

lukaseder avatar Apr 26 '17 14:04 lukaseder

Implemented through https://github.com/jOOQ/jOOL/pull/315

lukaseder avatar May 17 '17 07:05 lukaseder