Yes.
Class Exception
and class Error
both extend Throwable.
A Java method can "throw" an object of class Throwable
.
(We will do this later on in this chapter.)
For example, Scanner
threw
an exception when it tried to convert "rats" into an integer.
Exception
s are different from Error
s because
programs can be written to recover from Exception
s,
but programs can not be written to recover from Error
s.
The rest of this chapter discusses Exception
s.
Exception
s can be caught by a part of the program that
tries to recover from the problem.
(Recall that in these notes, classes are drawn as "clouds" and an arrow points from the child class to the parent class.)
Must a program catch Exception
s?