Quantcast

CompletionStage and checked exceptions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

CompletionStage and checked exceptions

Pavel Rappo
Hi,

It most likely has been discussed before, unfortunately I haven't found the
relevant link, but only a couple of threads where this has been mentioned
(e.g. [1]).

I was wondering why there's no readily available facility to call a computation
that can throw a checked exception? For example:

    cs.whenComplete((result, error) -> ((Closeable) c).close());

Thanks,
-Pavel

-------------------------------------------------------------------------------
[1] http://cs.oswego.edu/pipermail/concurrency-interest/2014-November/013168.html
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CompletionStage and checked exceptions

Viktor Klang


On Mon, Jan 30, 2017 at 12:22 PM, Pavel Rappo <[hidden email]> wrote:
Hi,

It most likely has been discussed before, unfortunately I haven't found the
relevant link, but only a couple of threads where this has been mentioned
(e.g. [1]).

I was wondering why there's no readily available facility to call a computation
that can throw a checked exception? For example:

    cs.whenComplete((result, error) -> ((Closeable) c).close());


My 2c: The jury's pretty much in when it comes to checked exceptions: what I do in Java is sprinkle it with sneakyThrows. (It's pretty easy to make it accept a lambda.)

This problem never comes up in Scala since it doesn't have checked exceptions, but if it did, it can easily be dealt with using scala.util.Try* (a heap-based equivalent of the stack-based try-catch)


* Interestingly, a Future in Scala is an eventual Try<T>
 
Thanks,
-Pavel

-------------------------------------------------------------------------------
[1] http://cs.oswego.edu/pipermail/concurrency-interest/2014-November/013168.html
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest



--
Cheers,

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Loading...