First, it is my strong opinion that the terms checked vs unchecked exceptions are imprecise, as it descriptively misleads who is doing the checking or if the checking is voluntary. Therefore I would be using the following terms in this question, so that people not aware of the difference might chip in an answer:
Motivation of Question:
I feel that the writers of standard Java utilities have committed misguided and inappropriate over-dependence on exceptions. The utility that is of my particular attention is the Integer.parseint(String) utility method.
Question:
If I am to rewrite the utility, to satisfy my annoyance against overuse of exceptions by utility writers, what would be the best way to go around this predicament? That would treat unacceptable string, but satisfying my ideology against the overuse of exceptions.
My immediate thinking to solving it would be
Since Java is debilitated/impoverished by the absence of Delegates in the language, I would have it as
Where
public interface CallBack<T,S> {
T mitigate(S value);
}
However, I doubt my quick-and-dirty solution is the best way of avoiding the use of exceptions. What are the alternative algorithms I could use to solve my ideological disagreement with the over-dependence on exceptions? Before I embark on writing a library of such utilities.
What you are looking for is the Maybe monad, implemented as the Optional interface in Java 8. This is a battle-proven approach which facilitates composition of functions in the face if possible "exceptions" anywhere within the composition chain.
One caveat with the above is that the complete API must support the Maybe monad for it to be truly useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With