Eroxl's Notes
Exceptions

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:

  1. Catching the exception and running code to address the problem.
  2. Propagating the exception back to its caller.

Handling

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) {  
	...  
}

Kinds of Exceptions

Checked

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.

Unchecked

The RuntimeException and any of it's subclasses are unchecked exceptions. Unchecked exceptions don't need to be handled by it's caller.