- Identify preconditions for the methods in classes you write.
- In each method check if its preconditions are met. If not, throw an appropriate exception.
- Include methods in your class that lets the user of the class test whether preconditions regarding the state of a class instance are met.
- Stick to the standard Java exception classes if possible.
Usually you can find one that is appropriate for your purposes
without having to create new Exception classes.
A short list of commonly used java unchecked exceptions:
- IndexOutOfBoundsException (unchecked)
- IllegalArgumentException (unchecked)
- IllegalStateException (unchecked)
- NoSuchElementException (unchecked)
- UnsupportedOperationException (unchecked)