 | Types of Exceptions
 | Checked Exceptions
 | extend Exception |
 | MUST be either |
 | explicitly caught by a surrounding catch block |
 | explicitly declared as a checked exception via
the throws clause |
|
 | Unchecked Exceptions
 | extend RuntimeException |
 | DOES NOT need an explicit catch block or throws
clause |
|
|
 | throw
 | "How you raise exceptions" |
 | Throw only classes of type Throwable - Exceptions extend
Throwable |
 | throw new java.io.IOException(); |
|
 | try, catch, finally
 | try blocks - "How you define the block of code
where exceptions are 'watched for'" |
 | catch clauses - "After an exception is thrown in a
try block, determine how to deal with it" |
 | finally clause - "After the try block is complete,
run this no matter what/how" |
|
 | Example
try {
//
//code that could throws IOException, among other exceptions
//
} catch (IOException e) {
//handle IOException
} catch (Exception ee) {
//catch any exception
} finally {
//clean up after the try block
}
|