• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java 8 In Action: Exception Handling in Lambdas

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Messrs. Urma, Fusco, and Mycroft:

Do you have any suggestions for handling checked (or even unchecked) exceptions in lambda expressions? Having to put a bulky try-catch block in a lambda expression seems to defeat the purpose. It just ruins the terse, functional style that lambdas make possible.

Scala has Try, and it helps. I haven't seen anything like that in the Java 8 API, so I've attempted to port the concept to Java 8:

https://github.com/bradleyscollins/try4j

Is there a better technique or paradigm already in Java 8 that I've overlooked?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, checked exceptions are indeed something that lambdas do not facilitate. If the functional interface's method doesn't include the exception in its throws class, then you must catch the exception within the lambda.

Note that unchecked exceptions don't have this problem; the exception will simply be propagated to the calling code (which may catch it or propagate it further).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic