Exception Handling
An exception (short for "exceptional event") is an unexpected event that occurs as a program is running.
Examples of exceptions:
- ArrayIndexOutOfBoundsException when you try to access a negative index of an array, or an index >= the array's length
- InputMismatchException when you enter an incorrect data type for a Scanner input (for example, entering a double when
nextInt()
is called)
Exceptions that occur are said to be thrown
Exception handling allows your programs to gracefully recover from exceptions
The Java mechanism for handling exceptions is the try-catch block