An exception is thrown by Java when a runtime error is encountered. The exception provides information about what kind of error occurred.
For example:
* An ArithmeticException
is thrown when your program tries to divide by 0.
* An IndexOutOfBoundsException
is thrown when your program tries to access an index that is out of bounds (for example str.charAt(-1);
, since there is no such thing as the -1 index).