To understand when (and what) you have to advertise in the
throws clause of the methods you write, keep in mind that an exception is thrown in any of the following four situations:
-
You call a method that throws a checked exception, for example, the FileInputStream constructor.
-
You detect an error and throw a checked exception with the throw statement (we cover the tHRow statement in the next section).
-
You make a programming error, such as a[-1] = 0 that gives rise to an unchecked exception such as an ArrayIndexOutOfBoundsException.
-
An internal error occurs in the virtual machine or runtime library.