5. Exception Name meaning
ArithmeticException Arithmetic error, such as divide-by-zero.
ArrayIndexOutOfBoundsExcepti
on
Array index is out-of-bounds.
ArrayStoreException Assignment to an array element of an
incompatible type.
ClassCastException Invalid cast.
IllegalArgumentException Illegal argument used to invoke a method.
IllegalMonitorStateException Illegal monitor operation, such as waiting
on an unlocked thread.
IllegalStateException Environment or application is in incorrect
state.
IllegalThreadStateException Requested operation not compatible with
the current thread state.
Java’s Built-in Unchecked Exceptions
6. Java’s Built-in Unchecked Exceptions (contd..)
Exception Name Meaning
NegativeArraySizeException Array created with a negative
size.
NullPointerException Invalid use of a null reference.
NumberFormatException Invalid conversion of a string to
a numeric format.
SecurityException Attempt to violate security.
StringIndexOutOfBounds Attempt to index outside the
bounds of a string.
UnsupportedOperationExcept
ion
An unsupported operation was
encountered.
8. throw
• The throw keyword in Java is used to explicitly throw
an exception from a method or any block of code. We
can throw either checked or unchecked exception.
• Syntax:
throw ThrowableInstance;
9. throws
• throws is a keyword in Java which is used in the
signature of method to indicate that this method might
throw one of the listed type exceptions.
• The caller to these methods has to handle the exception
using a try-catch block.
• We do this by including a throws clause in the method’s
declaration.
11. finally
• finally creates a block of code that will be
executed after a try /catch block has completed and
before the code following the try/catch block.
• The finally block will execute whether or not an
exception is thrown.
• If an exception is thrown, the finally block will
execute even if no catch statement matches the
exception.
12. finally (contd..)
• The finally clause is optional.
Note: each try statement requires at least one
catch or a finally clause.