One of the attributes that most strongly distinguishes expert programmers from less experienced ones is that experts strive for and usually achieve a high degree of code reuse. The Java platform libraries provide a basic set of unchecked exceptions that cover a large fraction of the exception-throwing needs of most APIs.
Reusing preexisting exceptions has several benefits.
- makes your API easier to learn because it matches established conventions with which programmers are already familiar.
- programs using your API are easier to read because they aren't cluttered with unfamiliar exceptions
-
NullPointerException : Parameter value is
null
where prohibited -
IllegalArgumentException : Non-
null
parameter value is inappropriate - IllegalStateException : Object state is inappropriate for method invocation
- IndexOutOfBoundsException : Index parameter is out of range
- UnsupportedOperationException : Object does not support the method
No comments:
Post a Comment