File operations can typically cause unexpected situations that the program is not capable of handling (for example, if we try to open a file for reading, and specify a filename that does not exist). Such situations are called exceptions. They are classified according to the type of inconvenient that has happened, and they must be handled by the program by inserting suitable Java code (see Unit 10).
For this unit, it is sufficient to know that the methods that make use of statements that can generate an exception must declare this.
For example, the methods for opening a file for reading can generate an exception of type IOException. Therefore, all methods that call such methods must declare explicitly that they can themselves generate an exception of that type.
The type of exception that a method can generate is specified in the throws clause, which must be added to the method declaration before the body of the method. For example:
public static void main(String args) throws IOException