7.1 Basic exceptions
An exception condition is a problem that prevents the
continuation of the method or scope that you are in.
You cant deal with the problem, so must throw an exception.
When you throw an exception, serveral things happen:
-
The exception object is created.
-
The current path of exception is stopped and the handle for
exception object is ejected.
-
The exception-handling mechanism takes over and begins to
look for an approptiate place to continue.
There are two constructors in all the standard exceptions:
-
default constructor
-
takes a String argument
if ( t == null )
throw new NullPointerException();
if ( t == null )
throw new NullPointerException("HERE!");
The keyword throw causes a number of relatively things
to happen:
-
It executes the new-expression to create an object
-
The object is, in effect, "returned" from the method.
A simpliest way to think about exception handling is as
an alternate return mechanism.