The Exception class is part of the Java library. An exception is an instance of that class or one of its subclasses.
An exception can be thrown by a method when it encounters a problem that it wants the caller to handle. The caller handles the exception by:
To handle an exception a try-catch block is used
try {
...
} catch (MyException e) {
...
}
The catch will only catch subclasses of the provided exception. In this case MyException.
These catch blocks can be chained to handle different exceptions
try {
...
} catch (MyException e) {
...
} catch (MyOtherException e) {
...
}
Any exceptions that are not a subclass of RuntimeException are considered checked exceptions. Methods that throw checked exceptions must clarify which exception they throw in their declaration.
The RuntimeException and any of it's subclasses are unchecked exceptions. Unchecked exceptions don't need to be handled by it's caller.