September 2011
Beginner
650 pages
15h 47m
English
The preceding examples have been catching exceptions generated automatically by the JVM. However, it is possible to manually throw an exception by using the throw statement. Its general form is shown here:
throw exceptOb;
Here, exceptOb must be an object of an exception class derived from Throwable.
Here is an example that illustrates the throw statement by manually throwing an ArithmeticException:

Notice how the ArithmeticException was created using new in the throw statement. Remember, throw throws an object. Thus, you must create an object for it to throw. That is, you can’t just throw a type.
Read now
Unlock full access