Checked and Unchecked
Exceptions
- Compiler tracks only checked exceptions.
- Checked exceptions are in general thrown for reasons beyond the
programmer's control. Input, output operations may fail and
throw exceptions (e.g. IOException, FileNotFoundException
,
...)
- Unchecked exceptions are, generally, the programmer's fault,
as the corresponding condition should not occur at all.
- NullPointerException and
IndexOutOfBoundsException
are not checked.
- Two approaches for dealing with checked exceptions
- Declare the exception in the method header, indicating method may throw
this type of exception
- Catch the exception