Item 60 - Favor the use of standard exceptions

From Effective Java 2/e by Joshua Bloch

Benefits

  1. It makes your API easier to learn and use because it matches established conventions with which programmers are already familiar
  2. Programs using your API are easier to read because they aren’t cluttered with unfamiliar exceptions
  3. Fewer exception classes mean a smaller memory footprint and less time spent loading classes
Exception Occasion for Use
IllegalArgumentException Non-null parameter value is inappropriate
IllegalStateException Object state is inappropriate for method invocation
NullPointerException Parameter value is null where prohibited
IndexOutOfBoundsException Index parameter value is out of range
ConcurrentModificationException Concurrent modification of an object has been detected where it is prohibited
UnsupportedOperationException Object does not support method

Posted by The Finest Artist