The output you see is the call stack trace that tells you where the exception occurred. It provides specific information about which methods were called in order to get to the method where the exception occurred.
The try/catch statement allows the programmer to deal with exceptions so
that they do not cause the program to terminate. The structure of the
try/catch statement looks as follows:
A try may be followed by only a finally, or simply one or more catch blocks, or one or more catch blocks followed by a finally. The code in the finally block executes regardless of whether an exception is thrown. A good use of the finally block is to ensure that a file is closed once its contents have been read.
If a method contains a line of code that may throw an exception, the code
may be placed in a try block, or the method header may declare that the
method propagates the exception. This means that if an exception occurs, it
will be passed along to the caller of the method. The following code
demonstrates a method that propagates am exception to its caller.
The caller of this method must then also propagate the exception, or place the call to the method in a try block.
You may have noticed that for some types of exceptions the compiler complains if you do not either propgate them or catch them whereas other types of exceptions appear at runtime without any warning. Any exception that derives from RuntimeException is an unchecked exception. Unchecked exceptions need not be caught or propagated. Any exception not derived from RuntimeException is a checked exception and must be caught or propagated.
Many people think that checked excceptions were a mistake. See the following web pages for a discussion of checked exceptions.
To create your own exceptions, you merely need to define a class that
extends Exception (or RuntimeException if you want to define an unchecked
exception). Your exception can then be used like any other exception. Also,
remember that an exception is an object like everything else in Java. To
create and throw a new exception object you simply use the new operator to
create an instance of your exception class and use the keyword