When I compile the code below, I get the following error:
/home/prakashs/composite_indexes/src/main/java/com/spakai/composite/TwoKeyLookup.java:22: error: un
Checked Exceptions are much older than Java promises and do not work well with them as of Java 8. Technically speaking, BiFunction does not declare throwing any checked Exception. As such, your findCommonMatch
, which you pass to thenCombine
, can not throw them either.
Make NoMatchException
unchecked by inheriting from RuntimeException
. Also remove the misleading throws
declaration from the lookup method — it is not throwing anything — the code, being encapsulated within promise, is going to throw, not method creating promise.
Exceptions thrown within promises are by design completely invisible to code, that creates them and subscribes to them. Instead you are usually expected to use unchecked exceptions and handle them in a way, specific for particular promise library (see documentation of CompletionStage for details on it's exception handling facilities).