Exceptions Handling
This lesson lists issues to be cognizant of when working with Java exceptions.
We'll cover the following...
Notes on Exceptions
Use exceptions for exceptional situations and not for ordinary control flow.
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.
Runtime exceptions should be used to indicate programming errors only.
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 newError
subclasses. Therefore, all of the unchecked throwables needed should subclassRuntimeException
.Favor the use of standard exceptions rather than creating new ones to make code easier to comprehend and familiar.
Exception Name Used For IllegalArgumentException
Throw this exception when a ...