Exceptions Handling

This lesson lists issues to be cognizant of when working with Java exceptions.

We'll cover the following...

Notes on Exceptions

  1. Use exceptions for exceptional situations and not for ordinary control flow.

  2. Use checked exceptions for conditions from which the caller can reasonably be expected to recover. Checked exceptions force the programmer to deal with exceptional conditions, greatly enhancing reliability.

  3. Runtime exceptions should be used to indicate programming errors only.

  4. Don't subclass Error to create new subtypes. The general convention is that errors are reserved for use by the JVM to indicate resource deficiencies, invariant failures, or other conditions that make it impossible to continue execution. Given this convention, it’s best not to implement any new Error subclasses. Therefore, all of the unchecked throwables needed should subclass RuntimeException.

  5. Favor the use of standard exceptions rather than creating new ones to make code easier to comprehend and familiar.

    Exception NameUsed For

    IllegalArgumentException

    Throw this exception when a ...