当我编译下面的代码时,我收到以下错误:
/home/prakashs/composite_indexes/src/main/java/com/spakai/composite/TwoKeyLookup.java:22: error: unreported exception NoMatchException; must be caught or declared to be thrown
CompletableFuture<Set<V>> result = calling.thenCombine(called, (s1, s2) -> findCommonMatch(s1, s2));
编码:
public CompletableFuture<Set<V>> lookup(K callingNumber, K calledNumber) throws NoMatchException {
CompletableFuture<Set<V>> calling = callingNumberIndex.exactMatch(callingNumber);
CompletableFuture<Set<V>> called = calledNumberIndex.exactMatch(calledNumber);
CompletableFuture<Set<V>> result = calling.thenCombine(called, (s1, s2) -> findCommonMatch(s1, s2));
return result;
}
public Set<V> findCommonMatch(Set<V> s1, Set<V> s2) throws NoMatchException {
Set<V> intersection = new HashSet<V>(s1);
intersection.retainAll(s2);
if (intersection.isEmpty()) {
throw new NoMatchException("No match found");
}
return intersection;
}
我已经宣布它被抛出。我错过了什么?