爲什麼下面的代碼片段java的「拋出」的條款不工作
private void getEvents() throws VersionNotFoundException{
gameRepository.findAll().forEach(game->{
HttpHeaders headers = new HttpHeaders();
String appVersion = getClass().getPackage().getImplementationVersion();
if (appVersion==null) {
throw new VersionNotFoundException();
}
headers.set("X-TBA-App-Id","4205:"+this.getClass().getPackage().getImplementationVersion());
HttpEntity<?> requestEntity = new HttpEntity<>(headers);
restTemplate.exchange(getEventsForYearString, HttpMethod.GET,requestEntity , Event.class, game.getYear());
});
}
private class VersionNotFoundException extends Exception {
}
一類導致線路throw new VersionNotFoundException();
提出一個編譯器錯誤VersionNotFoundException
must be caught or declared to be thrown
?它非常清楚地被宣佈爲被拋出。
你應該定義會因lambda函數 –
,你也應該遵循Java命名約定。 –
@LewBloch你能詳細說明一下嗎?我見過的大多數java命名約定都會考慮這種兼容性。 –