Topics

Leave a Reply

49 Comments on "Java 8 Lambda Basics 18 – An Exception Handling Approach"

Notify of
avatar

Tobias
Guest
Tobias
3 months 19 days ago
A solution, that would be more elegant is to use a distinct class for the wrapper. Using a class will allow to store the exception caught and to react on it at the call-site.Here is how this works:1. Separate the two concerns (computation and printing), that are in the current lambda: // …. process(someNumbers, key, (v, k) -> print(v / k)); } private static void print(Object value) { System.out.println(value); }Ok. That alone won't help for sure ;)2. Create a wrapper-class class Try implements BiConsumer<Integer, Integer> { private Consumer<Exception> onException = null; private Consumer<Object> next; private BiFunction<Integer, Integer, Object> action; public… Read more »
Drogba
Guest
Drogba
3 months 28 days ago

This tutorial just extract the exception handling code to wrap it in another method by chaining the lambda expression. It still looks a bit stupid and not elegant enough to me. Maybe it's the limitation of java syntax. Hope someone will figure out a better way to handle exception like this. And also, not mention the problem of cannot specify what exception coming from the consumer as we don't know yet.

Wyatt Towne
Guest
Wyatt Towne
4 months 20 days ago

So, essentially, this method of handling exceptions with lambdas is just for elegancy in the code? It is still really cool, I am just curious if anyone can clarify that for me.

Balkrushna Wagh
Guest
Balkrushna Wagh
6 months 1 day ago

Yours videos are amazing !!But I don't understand the use of wrapper lambda here. First of all you did not put try catch block in original lambda because it doesn't know about what operation Consumer brings in. The same thing will happen with wrapper lambda.

Balkrushna Wagh
Guest
Balkrushna Wagh
6 months 1 day ago

Yours videos are amazing !!But I don't understand the use of wrapper lambda here. First of all you did not put try catch block in original lambda because it doesn't know about what operation Consumer brings in. The same thing will happen with wrapper lambda.

disekjoumoer
Guest
disekjoumoer
6 months 6 days ago

You skipped the point of what if the exception is not an ArithmeticException, Very confusing for learners and poor form.

disekjoumoer
Guest
disekjoumoer
6 months 7 days ago

You skipped the point of what if the exception is not an ArithmeticException, Very confusing for learners and poor form.

Gaurav Nigam
Guest
Gaurav Nigam
7 months 19 days ago

I watched this video atleast 10 times to understand how the wrapper method is created. One of the best tutorials on Lambda I have seen on you tube. Hats Off to this guy. Explained everything in evolutionary way. Just Brilliant…

Gaurav Nigam
Guest
Gaurav Nigam
7 months 20 days ago

I watched this video atleast 10 times to understand how the wrapper method is created. One of the best tutorials on Lambda I have seen on you tube. Hats Off to this guy. Explained everything in evolutionary way. Just Brilliant…

Jose Luis Romero
Guest
Jose Luis Romero
7 months 25 days ago

Why do u repeat so many times your explanations?!, it is a video, if someone didn't catch something and wants to hear/watch again and again something, just has to rewind it

1 2 3 4
wpDiscuz