Topics

Leave a Reply

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

Notify of
avatar

kleavenae
Guest
kleavenae
13 days 4 minutes ago

It would be nice if I could do this:catchSpecificExceptions(Someclass::method, param1, param2);It's equivalent to this:try { Someclass.method(param1, param2);}catch(SpecificException1 e) { dosomething();}catch(SpecificException2 e) { dosomethingelse();}catch(SpecificException3 e) { somethingelse();}But as you can see, it's quite sorter 😀

Yoyo Cob
Guest
Yoyo Cob
1 month 11 days ago

At the end of the video, you mentioned about Generic types, could you write an generic type version of the wrapperLambda function? Thanks a lot. Great Video!!!

Amanuel Alemayehu
Guest
Amanuel Alemayehu
2 months 4 days ago
Thank you! Best tutorial. I wrote the following simple Generic wrapper: import java.util.Arrays;import java.util.List;import java.util.function.BiConsumer; public class LambdaExample{ public static void main(String[] args){ List<Integer> numbers = Arrays.asList(2,3,7,10,9,1,110); int key = 1; process(numbers,key,wrapperConsumer((Integer i,Integer j)-> System.out.println(i/j), ArithmeticException.class)); } private static <T> void process(List<T> values, T key, BiConsumer<T, T> consumer){ values.forEach(i->consumer.accept(i,key)); } private static <T, E extends Exception> BiConsumer<T, T> wrapperConsumer(BiConsumer<T, T> consumer, Class<E> exClass){ return (i,j) -> { try{ consumer.accept(i,j); }catch(Exception e){ E clazz = exClass.cast(e); System.err.println( "Exception Message: " + clazz .getMessage()); } }; }}
livestupid thinkbrilliant
Guest
livestupid thinkbrilliant
3 months 27 days ago

so even now if the operation is changed and if some other exception happens then it will not be handled and it will be thrown as Unhandled exception… what is the point of wrapper without generic exception being caught..

dhananjay patade
Guest
dhananjay patade
4 months 8 hours ago

Nice video,, feel like AOP of java 🙂

Narayan Sampath
Guest
Narayan Sampath
4 months 4 days ago

now my company people will have even more complex looking hard to understand programs to look at unless they move to 1.8 beast mode… ha ha

Anurag Kumar
Guest
Anurag Kumar
5 months 3 days ago

Thanks a lot. Appreciate your effort to bring this to us:)

Rajat Verma
Guest
Rajat Verma
5 months 5 days ago

Lambda Version of Inception Movie 😉

Rahul Kumar
Guest
Rahul Kumar
7 months 23 days ago

This approach holds true in case of runtime exceptions. But this does not work for checked exceptions. I faced this issue while coding for work. Need to reach out to the internet to see how this could be handled.

Guram Kankava
Guest
Guram Kankava
8 months 9 days ago

Thank you very much, its quite hard concept to understand for me watched probably 10 times form 4:40, i think i understood eventually. thank you very much.

wpDiscuz