Was functional-Try already discussed?
Justin Dekeyser
justin.dekeyser at gmail.com
Wed May 6 05:29:22 UTC 2020
Hi everyone,
I am new to the OpenJDK community and I'm using Java fora small decade now,
first as a hobby, then in my academic studies and my PhD in maths, and now
as a professional developer in IT companies. I'm quite active on forum to
help people, I've helped teaching students in the university, I read a lot
of posts on blogs, and so many times I'm facing people having trouble with
checked exceptions.
The situation in my current job makes clarifies what I mean. People usually
like declaring their own exception super class as "BusinessException", then
deriving it in many subclasses to describe more accurate failure reasons.
The problem they face is that when they declare their class as *checked
Exception*, they cannot use the mechanism of Optional and Stream, for an
obvious reason. Usually they prefer Optional and Stream, so they end up by
subclassing RuntimeException.
I find it so sad because, when interfacing services, you often forget about
declaring those unchecked exceptions, and the client is not aware of what's
happening! I think you loose all the benefit of the exception mechanism in
Java here for a very bad reason.
In my job I finally rectified (partially, because the code base is huge)
the situation by implementing a "functional" Try in the same spirit than
the Optional. People are quite happy with it. I can invest more time in its
development but I think this small library could help more people about
turning their exception in something clean again. So maybe it could be
useful for the whole community. (I already discussed it with my boss, there
will be no copyright problem.)
There exists similar projects around the world (in the Vavr lib for
example) and Scala offers this as a basic feature, which basically means
that people could appreciate the enhancement!
I am wondering if the Try interface would be interesting for OpenJDK, if
they have been discussions about it, and what were the decisions about such
a library? In my opinion, it may be a good complement to the Optional and
the Stream interfaces to allow a functional style while keeping this cool
feature of checked exceptions.
Best regards,
Justin Dekeyser
More information about the core-libs-dev
mailing list