I have this code:
private void save(List<String> items) throws IOException {
try (FileWriter fileWriter = new FileWriter(file, true)) {
for (String item : items) {
fileWriter.write(item);
}
// Error for: "Unhandled exception: java.io.Exception"
items.stream().forEach(fileWriter::write);
}
}
It should write each element from the list passed to file.
I'm learning java streams and wanted to write each element with forEach function but run into strange error. Even my function throws IOException my IDE and compiled still complains about uncaught exception.
Do you need to catch it in lambda itself? Can it be thrown to parent?