Java Reference
In-Depth Information
What Happens if an Exception Is Never Caught?
If every method up to and including the main method simply includes a throws clause for a
particular class of exceptions, then it may turn out that an exception of that class is thrown
but never caught. In such cases, when an exception is thrown but never caught, then for the
kinds of programs we have seen so far, the program ends with an error message giving the
name of the exception class. (In Chapter 17 we will discuss programs with windowing inter-
faces that are known as GUI programs . For GUI programs, if an exception is thrown but
never caught, then nothing happens, but if your code does not somehow account for the
thrown exception, then the user may be left in an unexplained situation.)
In a well-written program, every exception that is thrown should eventually be caught by a
catch block in some method.
Display 9.10 Hierarchy of Throwable Objects
All descendents of the class Throwable
can be thrown and caught in a catch
block.
Throwable
Error
Exception
These are checked
exceptions, which means
they are subject to the Catch
or Declare Rule.
RuntimeException
Errors, all of
which do not need
to be accounted for
in a catch block or
throws clause.
Exceptions
that must either be caught
in a catch block or
declared in a throws clause.
Exceptions that
do not need to
be accounted for in a
catch block or throws clause.
 
Search WWH ::




Custom Search