Practice & Assessment
Test your understanding of Exception Handling and I/O
Multiple Choice Questions
5Which exception type does the Java compiler require you to handle or declare with throws?
When does the finally block NOT execute?
What does try-with-resources guarantee?
Why should you wrap FileReader in BufferedReader?
When should a custom exception extend RuntimeException instead of Exception?
Coding Challenges
1CSV file parser with error handling
Write a method List<Map<String, String>> parseCsv(String filePath) that reads a CSV file where the first line is the header. Each subsequent line becomes a Map where keys are header names and values are the cell values. Use try-with-resources for file reading. Throw a custom CsvParseException (checked) if a row has a different number of columns than the header. The method must handle files with 100,000+ rows efficiently using buffered reading. Input: path to a CSV file. Output: List of Maps. Time estimate: 25–30 minutes.
Mini Project
Persistent Task Manager CLI
Build a command-line task manager that saves and loads tasks from a file. Define a Task class with id (int), title (String), done (boolean), and createdAt (String). Store tasks as lines in tasks.txt using the format: id|title|done|createdAt. Implement TaskStore with methods: load() reads the file on startup and returns List<Task> (handle FileNotFoundException gracefully), save(List<Task>) writes all tasks (use try-with-resources), add(String title), complete(int id), delete(int id), and list() prints all tasks. Create a custom TaskNotFoundException (unchecked) thrown by complete() and delete() when the id doesn't exist. The main loop should accept commands: add, done, delete, list, quit — and persist changes to the file after each mutating command.
