Lecture 8: Exceptions and File I/O

This lecture considers some of the ways in which errors can be signalled by code and highlights their weaknesses. It introduces exceptions as a safer and more flexible approach, noting that they interrupt normal flow of control in a program and cannot be ignored. Examples of standard Java exceptions are presented and the difference between checked and unchecked exceptions is explained. Consideration is given to how we intercept exceptions using try and catch blocks. Finally, the lecture looks at different ways of reading from text files, and how we deal with the exceptions that may occur during file I/O.