import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class MainSeven { private static int parseLine(String line) throws InvalidInputException { String trimmed = line.trim(); if (trimmed.isEmpty()) { throw new InvalidInputException(); } try { return Integer.parseInt(trimmed); } catch (NumberFormatException e) { throw new InvalidInputException(trimmed, e); } } public static void main(String[] args) { try (FileReader fr = new FileReader("scores.txt")) { BufferedReader br = new BufferedReader(fr); int sum = 0; String line; while ((line = br.readLine()) != null) { try { sum += parseLine(line); } catch (InvalidInputException e) { System.out.println(e.getMessage()); } } br.close(); System.out.println(sum); } catch (FileNotFoundException e) { System.out.println("File not found: " + e.getMessage()); } catch (IOException e) { System.out.println("IOException: " + e.getMessage()); } } }