This might be a little abstract, so we to concretize to User’s error vs. Programmer’s error. RuntimeException and all its child classes indicate a programmer’s error, while Exception and all its child classes indicate a user’s error:
Use checked exceptions for recoverable conditions and runtime exceptions for programming errors.
- FileNotFoundException: Can happen anytime, its not a programmer’s mistake but a user’s error (choose a wrong file, working with a read-only or full file system, etc.)
- SQLException: Something went wrong with the database operation. Try to recover or notify the user. This example fits very good to the above mentioned ‘recoverable’ condition but can be as well caused by a user’s error, e.g. an invalid search query.
- NullPointerException: Clearly a programmer’s error, don’t catch it but make it not happen.
- ArithmeticException: Happens for example when you divide by zero. A programmer’s error. Don’t divide by zero.
- UnsupportedOperationException: Thrown for example by immutable implementations of Collection (e.g.
Collections.unmodifiableList()). It’s the responsibility of the programmer to handle this case.